From 0e5f76186ee97eee4bd68e76bee2ea90b605d529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A4in=C3=B6=20M=C3=A4kel=C3=A4?= Date: Thu, 1 Jun 2023 10:05:46 +0300 Subject: [PATCH] seat: Allow binding to inert seats If a seat is destroyed while a client is trying to bind it, wlroots needs to create an inert seat resource instead of crashing. --- types/seat/wlr_seat.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/types/seat/wlr_seat.c b/types/seat/wlr_seat.c index 73758569..07b75af3 100644 --- a/types/seat/wlr_seat.c +++ b/types/seat/wlr_seat.c @@ -176,8 +176,9 @@ static struct wlr_seat_client *seat_client_create(struct wlr_seat *wlr_seat, static void seat_handle_bind(struct wl_client *client, void *_wlr_seat, uint32_t version, uint32_t id) { + // `wlr_seat` can be NULL if the seat global is being destroyed struct wlr_seat *wlr_seat = _wlr_seat; - assert(client && wlr_seat); + assert(client); struct wl_resource *wl_resource = wl_resource_create(client, &wl_seat_interface, version, id); @@ -185,6 +186,12 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat, wl_client_post_no_memory(client); return; } + wl_resource_set_implementation(wl_resource, &seat_impl, NULL, + seat_client_handle_resource_destroy); + wl_list_init(wl_resource_get_link(wl_resource)); + if (wlr_seat == NULL) { + return; + } struct wlr_seat_client *seat_client = wlr_seat_client_for_wl_client(wlr_seat, client); @@ -198,8 +205,7 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat, return; } - wl_resource_set_implementation(wl_resource, &seat_impl, - seat_client, seat_client_handle_resource_destroy); + wl_resource_set_user_data(wl_resource, seat_client); wl_list_insert(&seat_client->resources, wl_resource_get_link(wl_resource)); if (version >= WL_SEAT_NAME_SINCE_VERSION) { wl_seat_send_name(wl_resource, wlr_seat->name);