]> git.mdlowis.com Git - proto/labwc.git/commitdiff
project wide: clean up event listeners on shutdown
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 8 Feb 2025 14:48:50 +0000 (15:48 +0100)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Thu, 13 Mar 2025 08:33:51 +0000 (17:33 +0900)
This ensures all event listeners are removed before the emitting
wlroots object is being destroyed. This will be enforced with asserts
in wlroots 0.19 but there is no reason to not do it right now either.

This change in wlroots 0.19 is implemented via commit
8f56f7ca43257cc05c7c4eb57a0f541e05cf9a79
"Assert (almost all) signals have no attached listeners on destroy"

13 files changed:
include/decorations.h
include/labwc.h
include/layers.h
src/decorations/kde-deco.c
src/decorations/xdg-deco.c
src/idle.c
src/input/cursor.c
src/layers.c
src/output.c
src/seat.c
src/server.c
src/xdg.c
src/xwayland.c

index a77a7c58ea117970503b89a4ed6c58844c271ae7..4d23c14f84f7a1a0883339220a2e358b437b0fc7 100644 (file)
@@ -12,4 +12,7 @@ void xdg_server_decoration_init(struct server *server);
 void kde_server_decoration_update_default(void);
 void kde_server_decoration_set_view(struct view *view, struct wlr_surface *surface);
 
+void kde_server_decoration_finish(struct server *server);
+void xdg_server_decoration_finish(struct server *server);
+
 #endif /* LABWC_DECORATIONS_H */
index d7f43217f5396362190e467fae5e5075cfe4c7ad..8d9fe8cc4b2d832867a9004489457e108f827c0d 100644 (file)
@@ -435,6 +435,7 @@ struct constraint {
 
 void xdg_popup_create(struct view *view, struct wlr_xdg_popup *wlr_popup);
 void xdg_shell_init(struct server *server);
+void xdg_shell_finish(struct server *server);
 
 /*
  * desktop.c routines deal with a collection of views
@@ -539,6 +540,7 @@ void interactive_cancel(struct view *view);
 enum view_edge edge_from_cursor(struct seat *seat, struct output **dest_output);
 
 void output_init(struct server *server);
+void output_finish(struct server *server);
 void output_manager_init(struct server *server);
 struct output *output_from_wlr_output(struct server *server,
        struct wlr_output *wlr_output);
index 2b816a198e8379ef80abc17cb7f46cd1c93a6a1b..489bf9e21a011d67b17c944c1b2faf0af087add9 100644 (file)
@@ -37,6 +37,7 @@ struct lab_layer_popup {
 };
 
 void layers_init(struct server *server);
+void layers_finish(struct server *server);
 
 void layers_arrange(struct output *output);
 void layer_try_set_focus(struct seat *seat,
index 065f89fd562c3db5f3dc89bf61fc3c3ab1f7cc98..a615811b1e0e0b60b91f021d30e5a5463a6d713a 100644 (file)
@@ -133,3 +133,8 @@ kde_server_decoration_init(struct server *server)
        server->kde_server_decoration.notify = handle_new_server_decoration;
 }
 
+void
+kde_server_decoration_finish(struct server *server)
+{
+       wl_list_remove(&server->kde_server_decoration.link);
+}
index 219c33ac5722b282b1cbb74aeeeda19f88b1894c..d69808e65fc9d812214d902fe80c116f5503b07d 100644 (file)
@@ -127,3 +127,9 @@ xdg_server_decoration_init(struct server *server)
                &server->xdg_toplevel_decoration);
        server->xdg_toplevel_decoration.notify = xdg_toplevel_decoration;
 }
+
+void
+xdg_server_decoration_finish(struct server *server)
+{
+       wl_list_remove(&server->xdg_toplevel_decoration.link);
+}
index 844b17bb12a355fa285b518c6250dd5857034d12..568b680f3db077567e228789ff73ad53d9cabb2f 100644 (file)
@@ -17,9 +17,9 @@ struct lab_idle_manager {
        struct {
                struct wlr_idle_inhibit_manager_v1 *manager;
                struct wl_listener on_new_inhibitor;
+               struct wl_listener on_destroy;
        } inhibitor;
        struct wlr_seat *wlr_seat;
-       struct wl_listener on_display_destroy;
 };
 
 static struct lab_idle_manager *manager;
@@ -59,13 +59,10 @@ handle_idle_inhibitor_new(struct wl_listener *listener, void *data)
 }
 
 static void
-handle_display_destroy(struct wl_listener *listener, void *data)
+handle_inhibitor_manager_destroy(struct wl_listener *listener, void *data)
 {
-       /*
-        * All the managers will react to the display
-        * destroy signal as well and thus clean up.
-        */
-       wl_list_remove(&manager->on_display_destroy.link);
+       wl_list_remove(&manager->inhibitor.on_new_inhibitor.link);
+       wl_list_remove(&manager->inhibitor.on_destroy.link);
        zfree(manager);
 }
 
@@ -83,8 +80,9 @@ idle_manager_create(struct wl_display *display, struct wlr_seat *wlr_seat)
        wl_signal_add(&manager->inhibitor.manager->events.new_inhibitor,
                &manager->inhibitor.on_new_inhibitor);
 
-       manager->on_display_destroy.notify = handle_display_destroy;
-       wl_display_add_destroy_listener(display, &manager->on_display_destroy);
+       manager->inhibitor.on_destroy.notify = handle_inhibitor_manager_destroy;
+       wl_signal_add(&manager->inhibitor.manager->events.destroy,
+               &manager->inhibitor.on_destroy);
 }
 
 void
index 1a261ca953b271b66bdd359322a345e9e0bbd909..503c2d186700801c9ee428e0260f141097833e14 100644 (file)
@@ -1520,6 +1520,7 @@ void cursor_finish(struct seat *seat)
        wl_list_remove(&seat->request_cursor.link);
        wl_list_remove(&seat->request_set_shape.link);
        wl_list_remove(&seat->request_set_selection.link);
+       wl_list_remove(&seat->request_set_primary_selection.link);
 
        wlr_xcursor_manager_destroy(seat->xcursor_manager);
        wlr_cursor_destroy(seat->cursor);
index 6ce9527dbae62fcccff06f20c4256e9606a1269d..9b4dcdc802f0ac29e04841b38bea766933163f6f 100644 (file)
@@ -600,3 +600,9 @@ layers_init(struct server *server)
        wl_signal_add(&server->layer_shell->events.new_surface,
                &server->new_layer_surface);
 }
+
+void
+layers_finish(struct server *server)
+{
+       wl_list_remove(&server->new_layer_surface.link);
+}
index 2d0368a8f1fe374b4f8dd7f82985fdc9bfcfdaf1..1221376c81bbf42791b56410ca8f5db27bffdc43 100644 (file)
@@ -572,6 +572,15 @@ output_init(struct server *server)
        output_manager_init(server);
 }
 
+static void output_manager_finish(struct server *server);
+
+void
+output_finish(struct server *server)
+{
+       wl_list_remove(&server->new_output.link);
+       output_manager_finish(server);
+}
+
 static void
 output_update_for_layout_change(struct server *server)
 {
@@ -890,6 +899,15 @@ output_manager_init(struct server *server)
                &server->gamma_control_set_gamma);
 }
 
+static void
+output_manager_finish(struct server *server)
+{
+       wl_list_remove(&server->output_layout_change.link);
+       wl_list_remove(&server->output_manager_apply.link);
+       wl_list_remove(&server->output_manager_test.link);
+       wl_list_remove(&server->gamma_control_set_gamma.link);
+}
+
 struct output *
 output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
 {
index c72cb186c68f9ced14b25349c4eccd276530f84b..09729f38c4da529d42ba4b3d8a9a033898d7cb28 100644 (file)
@@ -588,6 +588,8 @@ seat_finish(struct server *server)
        struct seat *seat = &server->seat;
        wl_list_remove(&seat->new_input.link);
        wl_list_remove(&seat->focus_change.link);
+       wl_list_remove(&seat->virtual_pointer_new.link);
+       wl_list_remove(&seat->virtual_keyboard_new.link);
 
        struct input *input, *next;
        wl_list_for_each_safe(input, next, &seat->inputs, link) {
index 2c546309fcf77501ccaf02b8905df97c03f796b6..5333759390a1435e42f8ac9cd3735a56f156da36 100644 (file)
@@ -752,12 +752,26 @@ server_finish(struct server *server)
                wl_event_source_remove(sighup_source);
        }
        wl_display_destroy_clients(server->wl_display);
+
+       seat_finish(server);
+       output_finish(server);
+       xdg_shell_finish(server);
+       layers_finish(server);
+       kde_server_decoration_finish(server);
+       xdg_server_decoration_finish(server);
+       wl_list_remove(&server->new_constraint.link);
+       wl_list_remove(&server->output_power_manager_set_mode.link);
+       wl_list_remove(&server->tearing_new_object.link);
+
        wlr_backend_destroy(server->backend);
        wlr_allocator_destroy(server->allocator);
+
+       wl_list_remove(&server->renderer_lost.link);
        wlr_renderer_destroy(server->renderer);
-       seat_finish(server);
+
        workspaces_destroy(server);
        wlr_scene_node_destroy(&server->scene->tree.node);
+
        wl_display_destroy(server->wl_display);
        free(server->ssd_hover_state);
 }
index 4b8c9f96bdda54ee974af5dcbffbf0f35c91e7a3..145e739e1fc80ff6f4c4ca1207c49505e5c8358a 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -1012,3 +1012,10 @@ xdg_shell_init(struct server *server)
                &server->xdg_activation_new_token);
 }
 
+void
+xdg_shell_finish(struct server *server)
+{
+       wl_list_remove(&server->new_xdg_toplevel.link);
+       wl_list_remove(&server->xdg_activation_request.link);
+       wl_list_remove(&server->xdg_activation_new_token.link);
+}
index a295e03a9fa86f0aff47a9eccc714de6d7c4bb2f..c42e621354771d1bcb8b2c11095f475865574936 100644 (file)
@@ -1237,6 +1237,10 @@ void
 xwayland_server_finish(struct server *server)
 {
        struct wlr_xwayland *xwayland = server->xwayland;
+       wl_list_remove(&server->xwayland_new_surface.link);
+       wl_list_remove(&server->xwayland_server_ready.link);
+       wl_list_remove(&server->xwayland_xwm_ready.link);
+
        /*
         * Reset server->xwayland to NULL first to prevent callbacks (like
         * server_global_filter) from accessing it as it is destroyed