From 9ddaea14a1b24bf755417bffce792b0d4a23a87c Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 01:05:49 +0100 Subject: [PATCH] Listen to display destroy in wl-shell --- include/wlr/types/wlr_wl_shell.h | 2 ++ types/wlr_wl_shell.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 986f92e8..29446b04 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -12,6 +12,8 @@ struct wlr_wl_shell { struct wl_list popup_grabs; uint32_t ping_timeout; + struct wl_listener display_destroy; + struct { struct wl_signal new_surface; } events; diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index ee72856c..78154245 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -564,6 +564,12 @@ static void shell_bind(struct wl_client *wl_client, void *data, wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource)); } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_wl_shell *wl_shell = + wl_container_of(listener, wl_shell, display_destroy); + wlr_wl_shell_destroy(wl_shell); +} + struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) { struct wlr_wl_shell *wl_shell = calloc(1, sizeof(struct wlr_wl_shell)); if (!wl_shell) { @@ -581,6 +587,10 @@ struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) { wl_list_init(&wl_shell->surfaces); wl_list_init(&wl_shell->popup_grabs); wl_signal_init(&wl_shell->events.new_surface); + + wl_shell->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &wl_shell->display_destroy); + return wl_shell; } @@ -588,14 +598,14 @@ void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) { if (!wlr_wl_shell) { return; } + wl_list_remove(&wlr_wl_shell->display_destroy.link); struct wl_resource *resource = NULL, *temp = NULL; wl_resource_for_each_safe(resource, temp, &wlr_wl_shell->wl_resources) { struct wl_list *link = wl_resource_get_link(resource); wl_list_remove(link); } // TODO: destroy surfaces - // TODO: this segfault (wl_display->registry_resource_list is not init) - // wl_global_destroy(wlr_wl_shell->wl_global); + wl_global_destroy(wlr_wl_shell->wl_global); free(wlr_wl_shell); }