From a1ac2a2e93ffb3341253af30603cf16483d766bb Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 6 May 2025 09:20:46 +0200 Subject: [PATCH] Drop sway_output.events.disable In general wl_signal isn't well-suited for Sway: Sway doesn't need any modularity, and signals make it trickier to track down exactly what happens down the stack. Replace Sway's output disable signal with a simple list tracking for the only user. --- include/sway/layers.h | 5 ++++- include/sway/output.h | 5 +---- sway/desktop/layer_shell.c | 22 ++++++++++------------ sway/tree/output.c | 5 ++--- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/include/sway/layers.h b/include/sway/layers.h index fd6384e0e..27b5dde1b 100644 --- a/include/sway/layers.h +++ b/include/sway/layers.h @@ -9,7 +9,6 @@ struct sway_layer_surface { struct wl_listener map; struct wl_listener unmap; struct wl_listener surface_commit; - struct wl_listener output_destroy; struct wl_listener node_destroy; struct wl_listener new_popup; @@ -19,6 +18,8 @@ struct sway_layer_surface { struct sway_popup_desc desc; struct sway_output *output; + struct wl_list link; // sway_output.layer_surfaces + struct wlr_scene_layer_surface_v1 *scene; struct wlr_scene_tree *tree; struct wlr_layer_surface_v1 *layer_surface; @@ -41,4 +42,6 @@ struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface( void arrange_layers(struct sway_output *output); +void destroy_layers(struct sway_output *output); + #endif diff --git a/include/sway/output.h b/include/sway/output.h index f6354e0ed..756a0ec22 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -52,6 +52,7 @@ struct sway_output { bool enabled; list_t *workspaces; + struct wl_list layer_surfaces; // sway_layer_surface.link struct sway_output_state current; @@ -61,10 +62,6 @@ struct sway_output { struct wl_listener frame; struct wl_listener request_state; - struct { - struct wl_signal disable; - } events; - struct wlr_color_transform *color_transform; struct timespec last_presentation; diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 08b5b1de2..8c54d71aa 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -216,14 +216,6 @@ static struct sway_layer_surface *find_mapped_layer_by_client( return NULL; } -static void handle_output_destroy(struct wl_listener *listener, void *data) { - struct sway_layer_surface *layer = - wl_container_of(listener, layer, output_destroy); - - layer->output = NULL; - wlr_layer_surface_v1_destroy(layer->layer_surface); -} - static void handle_node_destroy(struct wl_listener *listener, void *data) { struct sway_layer_surface *layer = wl_container_of(listener, layer, node_destroy); @@ -257,10 +249,10 @@ static void handle_node_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&layer->surface_commit.link); wl_list_remove(&layer->node_destroy.link); wl_list_remove(&layer->new_popup.link); - wl_list_remove(&layer->output_destroy.link); layer->layer_surface->data = NULL; + wl_list_remove(&layer->link); free(layer); } @@ -475,6 +467,7 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { } surface->output = output; + wl_list_insert(&output->layer_surfaces, &surface->link); // now that the surface's output is known, we can advertise its scale wlr_fractional_scale_v1_notify_scale(surface->layer_surface->surface, @@ -492,9 +485,14 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { surface->new_popup.notify = handle_new_popup; wl_signal_add(&layer_surface->events.new_popup, &surface->new_popup); - surface->output_destroy.notify = handle_output_destroy; - wl_signal_add(&output->events.disable, &surface->output_destroy); - surface->node_destroy.notify = handle_node_destroy; wl_signal_add(&scene_surface->tree->node.events.destroy, &surface->node_destroy); } + +void destroy_layers(struct sway_output *output) { + struct sway_layer_surface *layer, *layer_tmp; + wl_list_for_each_safe(layer, layer_tmp, &output->layer_surfaces, link) { + layer->output = NULL; + wlr_layer_surface_v1_destroy(layer->layer_surface); + } +} diff --git a/sway/tree/output.c b/sway/tree/output.c index b02c1a2ce..42a403da8 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -136,12 +136,11 @@ struct sway_output *output_create(struct wlr_output *wlr_output) { output->detected_subpixel = wlr_output->subpixel; output->scale_filter = SCALE_FILTER_NEAREST; - wl_signal_init(&output->events.disable); - wl_list_insert(&root->all_outputs, &output->link); output->workspaces = create_list(); output->current.workspaces = create_list(); + wl_list_init(&output->layer_surfaces); return output; } @@ -284,7 +283,6 @@ void output_disable(struct sway_output *output) { } sway_log(SWAY_DEBUG, "Disabling output '%s'", output->wlr_output->name); - wl_signal_emit_mutable(&output->events.disable, output); // Remove the output now to avoid interacting with it during e.g., // transactions, as the output might be physically removed with the scene @@ -292,6 +290,7 @@ void output_disable(struct sway_output *output) { list_del(root->outputs, index); output->enabled = false; + destroy_layers(output); output_evacuate(output); }