From 6efc6a9db41fec64a77e136fc599c22293dcac49 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Thu, 16 Feb 2023 12:24:27 -0500 Subject: [PATCH] output: Add output_is_usable() helper --- include/labwc.h | 1 + src/foreign.c | 19 +++++++------------ src/osd.c | 5 ++--- src/output.c | 9 ++++++++- src/resistance.c | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index c95b1810..99aafb4c 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -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); diff --git a/src/foreign.c b/src/foreign.c index 788e0c88..9a576b16 100644 --- a/src/foreign.c +++ b/src/foreign.c @@ -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); } } diff --git a/src/osd.c b/src/osd.c index b1b6b843..782ce662 100644 --- 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 */ diff --git a/src/output.c b/src/output.c index 05808afe..53218508 100644 --- a/src/output.c +++ b/src/output.c @@ -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) diff --git a/src/resistance.c b/src/resistance.c index e59c6273..26ee84e6 100644 --- a/src/resistance.c +++ b/src/resistance.c @@ -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; }