From 24a479a50195988dbf622c6b7fe1f2263fd981b1 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Tue, 6 Jun 2023 17:52:52 +0300 Subject: [PATCH] drag: don't set icon's role_data Currently, an icon surface's role_data is set manually to a struct wlr_drag_icon, which is hacky, incorrect (as role_data is supposed to be the surface's role object, and drag icons don't have them), and will be disallowed by future changes. --- include/wlr/types/wlr_data_device.h | 2 ++ types/data_device/wlr_drag.c | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 0b425e88..ba067a62 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -98,6 +98,8 @@ struct wlr_drag_icon { struct wl_signal destroy; } events; + struct wl_listener surface_destroy; + void *data; }; diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c index 93614774..3e3f094e 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -106,6 +106,13 @@ out: wl_signal_emit_mutable(&drag->events.focus, drag); } +static void drag_icon_destroy(struct wlr_drag_icon *icon) { + icon->drag->icon = NULL; + wl_list_remove(&icon->surface_destroy.link); + wl_signal_emit_mutable(&icon->events.destroy, icon); + free(icon); +} + static void drag_destroy(struct wlr_drag *drag) { if (drag->cancelling) { return; @@ -145,7 +152,7 @@ static void drag_destroy(struct wlr_drag *drag) { } if (drag->icon != NULL) { - wlr_surface_destroy_role_object(drag->icon->surface); + drag_icon_destroy(drag->icon); } free(drag); } @@ -356,20 +363,18 @@ static void drag_icon_surface_role_commit(struct wlr_surface *surface) { } } -static void drag_icon_surface_role_destroy(struct wlr_surface *surface) { - assert(surface->role == &drag_icon_surface_role); - struct wlr_drag_icon *icon = surface->role_data; - - wl_signal_emit_mutable(&icon->events.destroy, icon); - free(icon); -} - const struct wlr_surface_role drag_icon_surface_role = { .name = "wl_data_device-icon", .commit = drag_icon_surface_role_commit, - .destroy = drag_icon_surface_role_destroy, }; +static void drag_icon_handle_surface_destroy(struct wl_listener *listener, + void *data) { + struct wlr_drag_icon *icon = + wl_container_of(listener, icon, surface_destroy); + drag_icon_destroy(icon); +} + static struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag, struct wlr_surface *surface) { struct wlr_drag_icon *icon = calloc(1, sizeof(struct wlr_drag_icon)); @@ -382,7 +387,8 @@ static struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag, wl_signal_init(&icon->events.destroy); - icon->surface->role_data = icon; + icon->surface_destroy.notify = drag_icon_handle_surface_destroy; + wl_signal_add(&surface->events.destroy, &icon->surface_destroy); drag_icon_surface_role_commit(surface);