output: Add output_is_usable() helper

This commit is contained in:
John Lindgren 2023-02-16 12:24:27 -05:00
parent fe7edf82d9
commit 6efc6a9db4
5 changed files with 20 additions and 18 deletions

View file

@ -416,6 +416,7 @@ void output_init(struct server *server);
void output_manager_init(struct server *server); void output_manager_init(struct server *server);
struct output *output_from_wlr_output(struct server *server, struct output *output_from_wlr_output(struct server *server,
struct wlr_output *wlr_output); struct wlr_output *wlr_output);
bool output_is_usable(struct output *output);
void output_update_usable_area(struct output *output); void output_update_usable_area(struct output *output);
void output_update_all_usable_areas(struct server *server, bool layout_changed); void output_update_all_usable_areas(struct server *server, bool layout_changed);
struct wlr_box output_usable_area_in_layout_coords(struct output *output); struct wlr_box output_usable_area_in_layout_coords(struct output *output);

View file

@ -110,21 +110,16 @@ void
foreign_toplevel_update_outputs(struct view *view) foreign_toplevel_update_outputs(struct view *view)
{ {
assert(view->toplevel.handle); assert(view->toplevel.handle);
struct wlr_box view_geo = view->current;
struct wlr_output_layout *layout = view->server->output_layout; struct wlr_output_layout *layout = view->server->output_layout;
struct output *output; struct output *output;
wl_list_for_each(output, &view->server->outputs, link) { wl_list_for_each(output, &view->server->outputs, link) {
if (output->wlr_output->enabled && !output->leased) { if (output_is_usable(output) && wlr_output_layout_intersects(
if (wlr_output_layout_intersects(layout, layout, output->wlr_output, &view->current)) {
output->wlr_output, &view_geo)) {
wlr_foreign_toplevel_handle_v1_output_enter( wlr_foreign_toplevel_handle_v1_output_enter(
view->toplevel.handle, output->wlr_output); view->toplevel.handle, output->wlr_output);
continue; } else {
}
}
wlr_foreign_toplevel_handle_v1_output_leave( wlr_foreign_toplevel_handle_v1_output_leave(
view->toplevel.handle, output->wlr_output); view->toplevel.handle, output->wlr_output);
} }
}
} }

View file

@ -407,11 +407,10 @@ osd_update(struct server *server)
struct output *output; struct output *output;
wl_list_for_each(output, &server->outputs, link) { wl_list_for_each(output, &server->outputs, link) {
destroy_osd_nodes(output); destroy_osd_nodes(output);
if (!output->wlr_output->enabled) { if (output_is_usable(output)) {
continue;
}
display_osd(output); display_osd(output);
} }
}
/* Outline current window */ /* Outline current window */
if (rc.cycle_preview_outlines) { if (rc.cycle_preview_outlines) {

View file

@ -26,7 +26,7 @@ static void
output_frame_notify(struct wl_listener *listener, void *data) output_frame_notify(struct wl_listener *listener, void *data)
{ {
struct output *output = wl_container_of(listener, output, frame); struct output *output = wl_container_of(listener, output, frame);
if (!output->wlr_output->enabled) { if (!output_is_usable(output)) {
return; return;
} }
@ -458,6 +458,13 @@ output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
return NULL; 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 */ /* returns true if usable area changed */
static bool static bool
update_usable_area(struct output *output) update_usable_area(struct output *output)

View file

@ -62,7 +62,7 @@ resistance_move_apply(struct view *view, double *x, double *y)
} }
wl_list_for_each(output, &server->outputs, link) { wl_list_for_each(output, &server->outputs, link) {
if (!output->wlr_output->enabled) { if (!output_is_usable(output)) {
continue; continue;
} }
@ -132,7 +132,7 @@ resistance_resize_apply(struct view *view, struct wlr_box *new_view_geo)
return; return;
} }
wl_list_for_each(output, &server->outputs, link) { wl_list_for_each(output, &server->outputs, link) {
if (!output->wlr_output->enabled) { if (!output_is_usable(output)) {
continue; continue;
} }