]> git.mdlowis.com Git - proto/labwc.git/commitdiff
output: Add output_is_usable() helper
authorJohn Lindgren <john@jlindgren.net>
Thu, 16 Feb 2023 17:24:27 +0000 (12:24 -0500)
committerJohn Lindgren <john@jlindgren.net>
Fri, 17 Feb 2023 11:59:39 +0000 (06:59 -0500)
include/labwc.h
src/foreign.c
src/osd.c
src/output.c
src/resistance.c

index c95b18106d25aa708636d8c0009cf9f6f98e8287..99aafb4cffd48952f35379d456055ff3fedd3548 100644 (file)
@@ -416,6 +416,7 @@ void output_init(struct server *server);
 void output_manager_init(struct server *server);
 struct output *output_from_wlr_output(struct server *server,
        struct wlr_output *wlr_output);
+bool output_is_usable(struct output *output);
 void output_update_usable_area(struct output *output);
 void output_update_all_usable_areas(struct server *server, bool layout_changed);
 struct wlr_box output_usable_area_in_layout_coords(struct output *output);
index 788e0c88da65248d2d23376cb08902f03e263e7c..9a576b16ed45d1dd873bbe7e2f21e021dcf4b066 100644 (file)
@@ -110,21 +110,16 @@ void
 foreign_toplevel_update_outputs(struct view *view)
 {
        assert(view->toplevel.handle);
-
-       struct wlr_box view_geo = view->current;
        struct wlr_output_layout *layout = view->server->output_layout;
-
        struct output *output;
        wl_list_for_each(output, &view->server->outputs, link) {
-               if (output->wlr_output->enabled && !output->leased) {
-                       if (wlr_output_layout_intersects(layout,
-                                       output->wlr_output, &view_geo)) {
-                               wlr_foreign_toplevel_handle_v1_output_enter(
-                                       view->toplevel.handle, output->wlr_output);
-                               continue;
-                       }
+               if (output_is_usable(output) && wlr_output_layout_intersects(
+                               layout, output->wlr_output, &view->current)) {
+                       wlr_foreign_toplevel_handle_v1_output_enter(
+                               view->toplevel.handle, output->wlr_output);
+               } else {
+                       wlr_foreign_toplevel_handle_v1_output_leave(
+                               view->toplevel.handle, output->wlr_output);
                }
-               wlr_foreign_toplevel_handle_v1_output_leave(
-                       view->toplevel.handle, output->wlr_output);
        }
 }
index b1b6b843b21a1a104a29e0e1a3b6064ff30bffa0..782ce6621ecb2dce1983d9001d4ed8ed0591c3a8 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -407,10 +407,9 @@ osd_update(struct server *server)
        struct output *output;
        wl_list_for_each(output, &server->outputs, link) {
                destroy_osd_nodes(output);
-               if (!output->wlr_output->enabled) {
-                       continue;
+               if (output_is_usable(output)) {
+                       display_osd(output);
                }
-               display_osd(output);
        }
 
        /* Outline current window */
index 05808afef448be2463ee49c1d889cc7c718f49ce..53218508c79b43c10c13bd2123d4211d35efe590 100644 (file)
@@ -26,7 +26,7 @@ static void
 output_frame_notify(struct wl_listener *listener, void *data)
 {
        struct output *output = wl_container_of(listener, output, frame);
-       if (!output->wlr_output->enabled) {
+       if (!output_is_usable(output)) {
                return;
        }
 
@@ -458,6 +458,13 @@ output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
        return NULL;
 }
 
+bool
+output_is_usable(struct output *output)
+{
+       /* output_is_usable(NULL) is safe and returns false */
+       return output && output->wlr_output->enabled && !output->leased;
+}
+
 /* returns true if usable area changed */
 static bool
 update_usable_area(struct output *output)
index e59c62734713c6f6a5c7504122df4d2f3d14a59d..26ee84e6b4c40cfd92984a17ce7db3e54e7aab0e 100644 (file)
@@ -62,7 +62,7 @@ resistance_move_apply(struct view *view, double *x, double *y)
        }
 
        wl_list_for_each(output, &server->outputs, link) {
-               if (!output->wlr_output->enabled) {
+               if (!output_is_usable(output)) {
                        continue;
                }
 
@@ -132,7 +132,7 @@ resistance_resize_apply(struct view *view, struct wlr_box *new_view_geo)
                return;
        }
        wl_list_for_each(output, &server->outputs, link) {
-               if (!output->wlr_output->enabled) {
+               if (!output_is_usable(output)) {
                        continue;
                }