diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 12b25e45..70d79a19 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -15,6 +15,8 @@ wlr_touch_grab_interface wlr_data_device_touch_drag_interface; struct wlr_data_device_manager { struct wl_global *global; + + struct wl_listener display_destroy; }; struct wlr_data_offer { diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 919d0e32..cf8c3f8f 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -78,6 +78,9 @@ static void wl_compositor_bind(struct wl_client *wl_client, void *data, } void wlr_compositor_destroy(struct wlr_compositor *compositor) { + if (compositor == NULL) { + return; + } wl_list_remove(&compositor->display_destroy.link); wl_global_destroy(compositor->wl_global); free(compositor); diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index a8d69cc0..dacb2a45 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -949,6 +949,21 @@ static void data_device_manager_bind(struct wl_client *client, NULL, NULL); } +void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { + if (!manager) { + return; + } + wl_list_remove(&manager->display_destroy.link); + wl_global_destroy(manager->global); + free(manager); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_data_device_manager *manager = + wl_container_of(listener, manager, display_destroy); + wlr_data_device_manager_destroy(manager); +} + struct wlr_data_device_manager *wlr_data_device_manager_create( struct wl_display *display) { struct wlr_data_device_manager *manager = @@ -967,13 +982,8 @@ struct wlr_data_device_manager *wlr_data_device_manager_create( return NULL; } - return manager; -} + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); -void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { - if (!manager) { - return; - } - wl_global_destroy(manager->global); - free(manager); + return manager; }