aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVäinö Mäkelä <vaino.o.makela@gmail.com>2023-06-01 10:05:46 +0300
committerSimon Ser <contact@emersion.fr>2023-06-03 10:43:12 +0000
commit0e5f76186ee97eee4bd68e76bee2ea90b605d529 (patch)
tree56e9fecdfaa95d9e25e0f67449b1194cef3a39ac
parent52b93f7eb41bd96870c935013fe6d1e36facba5c (diff)
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.
-rw-r--r--types/seat/wlr_seat.c12
1 files 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);