From dac518f3fec8f11d5d61706d76f506ca327071d8 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Mon, 9 Jan 2023 16:02:12 +0200 Subject: [PATCH] fullscreen-shell: Add missing compositor destroy listener Handles the 'BUG: layer_list is not empty after shutdown' warning. Fixes: #299 Signed-off-by: Marius Vlad --- fullscreen-shell/fullscreen-shell.c | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/fullscreen-shell/fullscreen-shell.c b/fullscreen-shell/fullscreen-shell.c index ab3acc15..552e9316 100644 --- a/fullscreen-shell/fullscreen-shell.c +++ b/fullscreen-shell/fullscreen-shell.c @@ -42,10 +42,8 @@ struct fullscreen_shell { struct wl_client *client; struct wl_listener client_destroyed; + struct wl_listener destroy_listener; struct weston_compositor *compositor; - /* XXX: missing compositor destroy listener - * https://gitlab.freedesktop.org/wayland/weston/issues/299 - */ struct weston_layer layer; struct wl_list output_list; @@ -846,6 +844,28 @@ bind_fullscreen_shell(struct wl_client *client, void *data, uint32_t version, ZWP_FULLSCREEN_SHELL_V1_CAPABILITY_ARBITRARY_MODES); } +static void +fullscreen_shell_destroy(struct wl_listener *listener, void *data) +{ + struct fs_output *fs_output, *fs_output_next; + struct fs_client_surface *surf; + struct fullscreen_shell *shell = + container_of(listener, struct fullscreen_shell, destroy_listener); + + /* remove the curtain(s) */ + wl_list_for_each_safe(fs_output, fs_output_next, &shell->output_list, link) + fs_output_destroy(fs_output); + + if (!wl_list_empty(&shell->default_surface_list)) { + surf = container_of(shell->default_surface_list.prev, + struct fs_client_surface, link); + remove_default_surface(surf); + } + + weston_layer_fini(&shell->layer); + free(shell); +} + WL_EXPORT int wet_shell_init(struct weston_compositor *compositor, int *argc, char *argv[]) @@ -858,7 +878,16 @@ wet_shell_init(struct weston_compositor *compositor, if (shell == NULL) return -1; + shell->compositor = compositor; + + if (!weston_compositor_add_destroy_listener_once(compositor, + &shell->destroy_listener, + fullscreen_shell_destroy)) { + free(shell); + return 0; + } + wl_list_init(&shell->default_surface_list); shell->client_destroyed.notify = client_destroyed;