mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
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.
This commit is contained in:
parent
30616bcf0c
commit
24a479a501
2 changed files with 19 additions and 11 deletions
|
@ -98,6 +98,8 @@ struct wlr_drag_icon {
|
|||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
struct wl_listener surface_destroy;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue