commit a1ac2a2e93ffb3341253af30603cf16483d766bb
parent 56f2db062daa64a0df77a83823d85fec7c3a9f46
Author: Simon Ser <contact@emersion.fr>
Date: Tue, 6 May 2025 09:20:46 +0200
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.
Diffstat:
4 files changed, 17 insertions(+), 20 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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);
}