data-device: reset focused surface when destroyed

The surface may be destroyed before the struct wlr_seat_client.

Spotted by Consolatis.
This commit is contained in:
Simon Ser 2024-12-06 16:42:26 +01:00 committed by Alexander Orzechowski
parent a7ebe7c026
commit 71943b3b1e
2 changed files with 18 additions and 1 deletions

View file

@ -135,6 +135,7 @@ struct wlr_drag {
struct { struct {
struct wl_listener source_destroy; struct wl_listener source_destroy;
struct wl_listener seat_client_destroy; struct wl_listener seat_client_destroy;
struct wl_listener focus_destroy;
struct wl_listener icon_destroy; struct wl_listener icon_destroy;
} WLR_PRIVATE; } WLR_PRIVATE;
}; };

View file

@ -19,6 +19,14 @@ static void drag_handle_seat_client_destroy(struct wl_listener *listener,
wl_list_remove(&drag->seat_client_destroy.link); wl_list_remove(&drag->seat_client_destroy.link);
} }
static void drag_set_focus(struct wlr_drag *drag,
struct wlr_surface *surface, double sx, double sy);
static void drag_handle_focus_destroy(struct wl_listener *listener, void *data) {
struct wlr_drag *drag = wl_container_of(listener, drag, focus_destroy);
drag_set_focus(drag, NULL, 0, 0);
}
static void drag_set_focus(struct wlr_drag *drag, static void drag_set_focus(struct wlr_drag *drag,
struct wlr_surface *surface, double sx, double sy) { struct wlr_surface *surface, double sx, double sy) {
if (drag->focus == surface) { if (drag->focus == surface) {
@ -48,9 +56,12 @@ static void drag_set_focus(struct wlr_drag *drag,
} }
drag->focus_client = NULL; drag->focus_client = NULL;
drag->focus = NULL;
} }
wl_list_remove(&drag->focus_destroy.link);
wl_list_init(&drag->focus_destroy.link);
drag->focus = NULL;
if (!surface) { if (!surface) {
goto out; goto out;
} }
@ -99,6 +110,8 @@ static void drag_set_focus(struct wlr_drag *drag,
drag->focus = surface; drag->focus = surface;
drag->focus_client = focus_client; drag->focus_client = focus_client;
drag->focus_destroy.notify = drag_handle_focus_destroy;
wl_signal_add(&surface->events.destroy, &drag->focus_destroy);
drag->seat_client_destroy.notify = drag_handle_seat_client_destroy; drag->seat_client_destroy.notify = drag_handle_seat_client_destroy;
wl_signal_add(&focus_client->events.destroy, &drag->seat_client_destroy); wl_signal_add(&focus_client->events.destroy, &drag->seat_client_destroy);
@ -150,6 +163,7 @@ static void drag_destroy(struct wlr_drag *drag) {
if (drag->source) { if (drag->source) {
wl_list_remove(&drag->source_destroy.link); wl_list_remove(&drag->source_destroy.link);
} }
wl_list_remove(&drag->focus_destroy.link);
if (drag->icon != NULL) { if (drag->icon != NULL) {
drag_icon_destroy(drag->icon); drag_icon_destroy(drag->icon);
@ -410,6 +424,8 @@ struct wlr_drag *wlr_drag_create(struct wlr_seat_client *seat_client,
wl_signal_init(&drag->events.drop); wl_signal_init(&drag->events.drop);
wl_signal_init(&drag->events.destroy); wl_signal_init(&drag->events.destroy);
wl_list_init(&drag->focus_destroy.link);
drag->seat = seat_client->seat; drag->seat = seat_client->seat;
drag->seat_client = seat_client; drag->seat_client = seat_client;