seat: allow clients to bind to seat multiple times

This lets clients bind to a seat multiple times by re-using the existing
wlr_seat_client whenever a duplicate request happens.
Previously, an independant wlr_seat_client would be created and only
events from one would be processed.

Fixes #1023.
This commit is contained in:
Dominique Martinet 2018-06-04 08:31:27 +09:00
parent 1c5c8652c5
commit 51b9883ea0
3 changed files with 53 additions and 29 deletions

View file

@ -13,11 +13,11 @@
* managed by wlr_seat; some may be NULL. * managed by wlr_seat; some may be NULL.
*/ */
struct wlr_seat_client { struct wlr_seat_client {
struct wl_resource *wl_resource;
struct wl_client *client; struct wl_client *client;
struct wlr_seat *seat; struct wlr_seat *seat;
// lists of wl_resource // lists of wl_resource
struct wl_list wl_resources;
struct wl_list pointers; struct wl_list pointers;
struct wl_list keyboards; struct wl_list keyboards;
struct wl_list touches; struct wl_list touches;

View file

@ -44,7 +44,7 @@ static void drag_set_focus(struct wlr_drag *drag,
if (!drag->source && if (!drag->source &&
wl_resource_get_client(surface->resource) != wl_resource_get_client(surface->resource) !=
wl_resource_get_client(drag->seat_client->wl_resource)) { drag->seat_client->client) {
return; return;
} }

View file

@ -60,6 +60,12 @@ static void seat_client_handle_resource_destroy(
struct wl_resource *seat_resource) { struct wl_resource *seat_resource) {
struct wlr_seat_client *client = struct wlr_seat_client *client =
wlr_seat_client_from_resource(seat_resource); wlr_seat_client_from_resource(seat_resource);
wl_list_remove(wl_resource_get_link(seat_resource));
if (!wl_list_empty(&client->wl_resources)) {
return;
}
wlr_signal_emit_safe(&client->events.destroy, client); wlr_signal_emit_safe(&client->events.destroy, client);
if (client == client->seat->pointer_state.focused_client) { if (client == client->seat->pointer_state.focused_client) {
@ -108,34 +114,43 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat,
struct wlr_seat *wlr_seat = _wlr_seat; struct wlr_seat *wlr_seat = _wlr_seat;
assert(client && wlr_seat); assert(client && wlr_seat);
struct wlr_seat_client *seat_client = struct wl_resource *wl_resource =
calloc(1, sizeof(struct wlr_seat_client));
if (seat_client == NULL) {
wl_client_post_no_memory(client);
return;
}
seat_client->wl_resource =
wl_resource_create(client, &wl_seat_interface, version, id); wl_resource_create(client, &wl_seat_interface, version, id);
if (seat_client->wl_resource == NULL) { if (wl_resource == NULL) {
free(seat_client);
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
} }
seat_client->client = client;
seat_client->seat = wlr_seat; struct wlr_seat_client *seat_client =
wl_list_init(&seat_client->pointers); wlr_seat_client_for_wl_client(wlr_seat, client);
wl_list_init(&seat_client->keyboards); if (seat_client == NULL) {
wl_list_init(&seat_client->touches); seat_client = calloc(1, sizeof(struct wlr_seat_client));
wl_list_init(&seat_client->data_devices); if (seat_client == NULL) {
wl_list_init(&seat_client->primary_selection_devices); wl_resource_destroy(wl_resource);
wl_resource_set_implementation(seat_client->wl_resource, &seat_impl, wl_client_post_no_memory(client);
seat_client, seat_client_handle_resource_destroy); return;
wl_list_insert(&wlr_seat->clients, &seat_client->link); }
if (version >= WL_SEAT_NAME_SINCE_VERSION) {
wl_seat_send_name(seat_client->wl_resource, wlr_seat->name); seat_client->client = client;
seat_client->seat = wlr_seat;
wl_list_init(&seat_client->wl_resources);
wl_list_init(&seat_client->pointers);
wl_list_init(&seat_client->keyboards);
wl_list_init(&seat_client->touches);
wl_list_init(&seat_client->data_devices);
wl_list_init(&seat_client->primary_selection_devices);
wl_signal_init(&seat_client->events.destroy);
wl_list_insert(&wlr_seat->clients, &seat_client->link);
} }
wl_seat_send_capabilities(seat_client->wl_resource, wlr_seat->capabilities);
wl_signal_init(&seat_client->events.destroy); wl_resource_set_implementation(wl_resource, &seat_impl,
seat_client, seat_client_handle_resource_destroy);
wl_list_insert(&seat_client->wl_resources, wl_resource_get_link(wl_resource));
if (version >= WL_SEAT_NAME_SINCE_VERSION) {
wl_seat_send_name(wl_resource, wlr_seat->name);
}
wl_seat_send_capabilities(wl_resource, wlr_seat->capabilities);
} }
void wlr_seat_destroy(struct wlr_seat *seat) { void wlr_seat_destroy(struct wlr_seat *seat) {
@ -160,8 +175,11 @@ void wlr_seat_destroy(struct wlr_seat *seat) {
struct wlr_seat_client *client, *tmp; struct wlr_seat_client *client, *tmp;
wl_list_for_each_safe(client, tmp, &seat->clients, link) { wl_list_for_each_safe(client, tmp, &seat->clients, link) {
// will destroy other resources as well struct wl_resource *resource, *next_resource;
wl_resource_destroy(client->wl_resource); wl_resource_for_each_safe(resource, next_resource, &client->wl_resources) {
// will destroy other resources as well
wl_resource_destroy(resource);
}
} }
wl_global_destroy(seat->wl_global); wl_global_destroy(seat->wl_global);
@ -308,7 +326,10 @@ void wlr_seat_set_capabilities(struct wlr_seat *wlr_seat,
} }
} }
wl_seat_send_capabilities(client->wl_resource, capabilities); struct wl_resource *resource;
wl_resource_for_each(resource, &client->wl_resources) {
wl_seat_send_capabilities(resource, capabilities);
}
} }
} }
@ -317,7 +338,10 @@ void wlr_seat_set_name(struct wlr_seat *wlr_seat, const char *name) {
wlr_seat->name = strdup(name); wlr_seat->name = strdup(name);
struct wlr_seat_client *client; struct wlr_seat_client *client;
wl_list_for_each(client, &wlr_seat->clients, link) { wl_list_for_each(client, &wlr_seat->clients, link) {
wl_seat_send_name(client->wl_resource, name); struct wl_resource *resource;
wl_resource_for_each(resource, &client->wl_resources) {
wl_seat_send_name(resource, name);
}
} }
} }