Listen to display destroy in wl-shell

This commit is contained in:
emersion 2017-12-07 01:05:49 +01:00
parent 983ea3033f
commit 9ddaea14a1
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 14 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}