From 92fbfda2ca1906f1ddee29aeb5db1109b02b1b60 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Fri, 4 Nov 2022 00:07:20 +0300 Subject: [PATCH] drag-icon: use role object destroy handler --- include/wlr/types/wlr_data_device.h | 2 -- types/data_device/wlr_drag.c | 35 ++++++++++------------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 9f2481e6..697987b2 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -101,8 +101,6 @@ 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 9b48df32..7d419c15 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -116,8 +116,6 @@ static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) { } } -static void drag_icon_destroy(struct wlr_drag_icon *icon); - static void drag_destroy(struct wlr_drag *drag) { if (drag->cancelling) { return; @@ -156,7 +154,9 @@ static void drag_destroy(struct wlr_drag *drag) { wl_list_remove(&drag->source_destroy.link); } - drag_icon_destroy(drag->icon); + if (drag->icon != NULL) { + wlr_surface_destroy_role_object(drag->icon->surface); + } free(drag); } @@ -357,38 +357,31 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener, drag_destroy(drag); } - -static void drag_icon_destroy(struct wlr_drag_icon *icon) { +static void drag_icon_surface_role_commit(struct wlr_surface *surface) { + assert(surface->role == &drag_icon_surface_role); + struct wlr_drag_icon *icon = surface->role_data; if (icon == NULL) { return; } - drag_icon_set_mapped(icon, false); - wl_signal_emit_mutable(&icon->events.destroy, icon); - icon->surface->role_data = NULL; - wl_list_remove(&icon->surface_destroy.link); - free(icon); -} -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); + drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface)); } -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; if (icon == NULL) { return; } - - drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface)); + drag_icon_set_mapped(icon, false); + 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 struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag, @@ -405,9 +398,6 @@ static struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag, wl_signal_init(&icon->events.unmap); wl_signal_init(&icon->events.destroy); - wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy); - icon->surface_destroy.notify = drag_icon_handle_surface_destroy; - icon->surface->role_data = icon; if (wlr_surface_has_buffer(surface)) { @@ -417,7 +407,6 @@ static struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag, return icon; } - struct wlr_drag *wlr_drag_create(struct wlr_seat_client *seat_client, struct wlr_data_source *source, struct wlr_surface *icon_surface) { struct wlr_drag *drag = calloc(1, sizeof(struct wlr_drag));