Skip to content

Commit ad50173

Browse files
committed
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.
1 parent 8ac1f72 commit ad50173

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

include/sway/layers.h

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct sway_layer_surface {
1919
struct sway_popup_desc desc;
2020

2121
struct sway_output *output;
22+
struct wl_list link; // sway_output.layer_surfaces
23+
2224
struct wlr_scene_layer_surface_v1 *scene;
2325
struct wlr_scene_tree *tree;
2426
struct wlr_layer_surface_v1 *layer_surface;
@@ -41,4 +43,6 @@ struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
4143

4244
void arrange_layers(struct sway_output *output);
4345

46+
void destroy_layers(struct sway_output *output);
47+
4448
#endif

include/sway/output.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct sway_output {
5252

5353
bool enabled;
5454
list_t *workspaces;
55+
struct wl_list layer_surfaces; // sway_layer_surface.link
5556

5657
struct sway_output_state current;
5758

@@ -61,10 +62,6 @@ struct sway_output {
6162
struct wl_listener frame;
6263
struct wl_listener request_state;
6364

64-
struct {
65-
struct wl_signal disable;
66-
} events;
67-
6865
struct wlr_color_transform *color_transform;
6966

7067
struct timespec last_presentation;

sway/desktop/layer_shell.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,6 @@ static struct sway_layer_surface *find_mapped_layer_by_client(
216216
return NULL;
217217
}
218218

219-
static void handle_output_destroy(struct wl_listener *listener, void *data) {
220-
struct sway_layer_surface *layer =
221-
wl_container_of(listener, layer, output_destroy);
222-
223-
layer->output = NULL;
224-
wlr_layer_surface_v1_destroy(layer->layer_surface);
225-
}
226-
227219
static void handle_node_destroy(struct wl_listener *listener, void *data) {
228220
struct sway_layer_surface *layer =
229221
wl_container_of(listener, layer, node_destroy);
@@ -479,6 +471,7 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
479471
}
480472

481473
surface->output = output;
474+
wl_list_insert(&output->layer_surfaces, &surface->link);
482475

483476
// now that the surface's output is known, we can advertise its scale
484477
wlr_fractional_scale_v1_notify_scale(surface->layer_surface->surface,
@@ -496,9 +489,14 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
496489
surface->new_popup.notify = handle_new_popup;
497490
wl_signal_add(&layer_surface->events.new_popup, &surface->new_popup);
498491

499-
surface->output_destroy.notify = handle_output_destroy;
500-
wl_signal_add(&output->events.disable, &surface->output_destroy);
501-
502492
surface->node_destroy.notify = handle_node_destroy;
503493
wl_signal_add(&scene_surface->tree->node.events.destroy, &surface->node_destroy);
504494
}
495+
496+
void destroy_layers(struct sway_output *output) {
497+
struct sway_layer_surface *layer, *layer_tmp;
498+
wl_list_for_each_safe(layer, layer_tmp, &output->layer_surfaces, link) {
499+
layer->output = NULL;
500+
wlr_layer_surface_v1_destroy(layer->layer_surface);
501+
}
502+
}

sway/tree/output.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,11 @@ struct sway_output *output_create(struct wlr_output *wlr_output) {
136136
output->detected_subpixel = wlr_output->subpixel;
137137
output->scale_filter = SCALE_FILTER_NEAREST;
138138

139-
wl_signal_init(&output->events.disable);
140-
141139
wl_list_insert(&root->all_outputs, &output->link);
142140

143141
output->workspaces = create_list();
144142
output->current.workspaces = create_list();
143+
wl_list_init(&output->layer_surfaces);
145144

146145
return output;
147146
}
@@ -287,8 +286,8 @@ void output_disable(struct sway_output *output) {
287286
}
288287

289288
sway_log(SWAY_DEBUG, "Disabling output '%s'", output->wlr_output->name);
290-
wl_signal_emit_mutable(&output->events.disable, output);
291289

290+
destroy_layers(output);
292291
output_evacuate(output);
293292

294293
list_del(root->outputs, index);

0 commit comments

Comments
 (0)