Commit 96d790e7 authored by Neil Roberts's avatar Neil Roberts Committed by Kristian H. Kristensen

input: Emit events on all resources for a client

The Wayland protocol permits a client to request the pointer, keyboard
and touch multiple times from the seat global. This is very useful in a
component like Clutter-GTK where we are combining two libraries that use
Wayland together.

This change migrates the weston input handling code to emit the
events for all the resources for the client by using the newly added
wl_resource_for_each macro to iterate over the resources that are
associated with the focused surface's client.

We maintain a list of focused resources on the pointer and keyboard
which is updated when the focus changes. However since we can have
resources created after the focus has already been set we must add the
resources to the right list and also update any state.

Additionally when setting the pointer focus it will now send the
keyboard modifiers regardless of whether the focused client has a
pointer resource. This is important because otherwise if the client
gets the pointer later than you getting the keyboard then the
modifiers might not be up-to-date.

Co-author: Neil Roberts <neil@linux.intel.com>
parent 57388e44
......@@ -160,7 +160,6 @@ binding_key(struct weston_keyboard_grab *grab,
struct weston_keyboard *keyboard = grab->keyboard;
struct wl_display *display = keyboard->seat->compositor->wl_display;
resource = grab->keyboard->focus_resource;
if (key == b->key) {
if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
weston_keyboard_end_grab(grab->keyboard);
......@@ -168,9 +167,15 @@ binding_key(struct weston_keyboard_grab *grab,
keyboard->grab = &keyboard->input_method_grab;
free(b);
}
} else if (resource) {
} else if (!wl_list_empty(&keyboard->focus_resource_list)) {
serial = wl_display_next_serial(display);
wl_keyboard_send_key(resource, serial, time, key, state);
wl_resource_for_each(resource, &keyboard->focus_resource_list) {
wl_keyboard_send_key(resource,
serial,
time,
key,
state);
}
}
}
......@@ -181,12 +186,10 @@ binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
{
struct wl_resource *resource;
resource = grab->keyboard->focus_resource;
if (!resource)
return;
wl_keyboard_send_modifiers(resource, serial, mods_depressed,
mods_latched, mods_locked, group);
wl_resource_for_each(resource, &grab->keyboard->focus_resource_list) {
wl_keyboard_send_modifiers(resource, serial, mods_depressed,
mods_latched, mods_locked, group);
}
}
static const struct weston_keyboard_grab_interface binding_grab = {
......
......@@ -310,9 +310,8 @@ struct weston_pointer {
struct weston_seat *seat;
struct wl_list resource_list;
struct wl_list focus_resource_list;
struct weston_surface *focus;
struct wl_resource *focus_resource;
struct wl_listener focus_listener;
uint32_t focus_serial;
struct wl_signal focus_signal;
......@@ -336,9 +335,8 @@ struct weston_touch {
struct weston_seat *seat;
struct wl_list resource_list;
struct wl_list focus_resource_list;
struct weston_surface *focus;
struct wl_resource *focus_resource;
struct wl_listener focus_listener;
uint32_t focus_serial;
struct wl_signal focus_signal;
......@@ -431,9 +429,8 @@ struct weston_keyboard {
struct weston_seat *seat;
struct wl_list resource_list;
struct wl_list focus_resource_list;
struct weston_surface *focus;
struct wl_resource *focus_resource;
struct wl_listener focus_listener;
uint32_t focus_serial;
struct wl_signal focus_signal;
......
......@@ -435,15 +435,15 @@ destroy_selection_data_source(struct wl_listener *listener, void *data)
struct weston_seat *seat = container_of(listener, struct weston_seat,
selection_data_source_listener);
struct wl_resource *data_device;
struct wl_resource *focus = NULL;
struct weston_surface *focus = NULL;
seat->selection_data_source = NULL;
if (seat->keyboard)
focus = seat->keyboard->focus_resource;
if (focus) {
focus = seat->keyboard->focus;
if (focus && focus->resource) {
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
wl_resource_get_client(focus));
wl_resource_get_client(focus->resource));
if (data_device)
wl_data_device_send_selection(data_device, NULL);
}
......@@ -456,7 +456,7 @@ weston_seat_set_selection(struct weston_seat *seat,
struct weston_data_source *source, uint32_t serial)
{
struct wl_resource *data_device, *offer;
struct wl_resource *focus = NULL;
struct weston_surface *focus = NULL;
if (seat->selection_data_source &&
seat->selection_serial - serial < UINT32_MAX / 2)
......@@ -472,10 +472,10 @@ weston_seat_set_selection(struct weston_seat *seat,
seat->selection_serial = serial;
if (seat->keyboard)
focus = seat->keyboard->focus_resource;
if (focus) {
focus = seat->keyboard->focus;
if (focus && focus->resource) {
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
wl_resource_get_client(focus));
wl_resource_get_client(focus->resource));
if (data_device && source) {
offer = weston_data_source_send_offer(seat->selection_data_source,
data_device);
......@@ -629,18 +629,19 @@ bind_manager(struct wl_client *client,
WL_EXPORT void
wl_data_device_set_keyboard_focus(struct weston_seat *seat)
{
struct wl_resource *data_device, *focus, *offer;
struct wl_resource *data_device, *offer;
struct weston_data_source *source;
struct weston_surface *focus;
if (!seat->keyboard)
return;
focus = seat->keyboard->focus_resource;
if (!focus)
focus = seat->keyboard->focus;
if (!focus || !focus->resource)
return;
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
wl_resource_get_client(focus));
wl_resource_get_client(focus->resource));
if (!data_device)
return;
......
This diff is collapsed.
......@@ -2160,13 +2160,14 @@ static void
popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
{
struct weston_pointer *pointer = grab->pointer;
struct wl_resource *resource;
wl_fixed_t sx, sy;
if (pointer->focus_resource) {
wl_resource_for_each(resource, &pointer->focus_resource_list) {
weston_surface_from_global_fixed(pointer->focus,
pointer->x, pointer->y,
&sx, &sy);
wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
wl_pointer_send_motion(resource, time, sx, sy);
}
}
......@@ -2180,11 +2181,15 @@ popup_grab_button(struct weston_pointer_grab *grab,
struct wl_display *display = shseat->seat->compositor->wl_display;
enum wl_pointer_button_state state = state_w;
uint32_t serial;
struct wl_list *resource_list;
resource = grab->pointer->focus_resource;
if (resource) {
resource_list = &grab->pointer->focus_resource_list;
if (!wl_list_empty(resource_list)) {
serial = wl_display_get_serial(display);
wl_pointer_send_button(resource, serial, time, button, state);
wl_resource_for_each(resource, resource_list) {
wl_pointer_send_button(resource, serial,
time, button, state);
}
} else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
(shseat->popup_grab.initial_up ||
time - shseat->seat->pointer->grab_time > 500)) {
......@@ -4252,6 +4257,7 @@ debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
int send = 0, terminate = 0;
int check_binding = 1;
int i;
struct wl_list *resource_list;
if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
/* Do not run bindings on key releases */
......@@ -4298,10 +4304,9 @@ debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
}
if (send) {
resource = grab->keyboard->focus_resource;
if (resource) {
serial = wl_display_next_serial(display);
serial = wl_display_next_serial(display);
resource_list = &grab->keyboard->focus_resource_list;
wl_resource_for_each(resource, resource_list) {
wl_keyboard_send_key(resource, serial, time, key, state);
}
}
......@@ -4320,13 +4325,14 @@ debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
uint32_t mods_locked, uint32_t group)
{
struct wl_resource *resource;
struct wl_list *resource_list;
resource = grab->keyboard->focus_resource;
if (!resource)
return;
resource_list = &grab->keyboard->focus_resource_list;
wl_keyboard_send_modifiers(resource, serial, mods_depressed,
mods_latched, mods_locked, group);
wl_resource_for_each(resource, resource_list) {
wl_keyboard_send_modifiers(resource, serial, mods_depressed,
mods_latched, mods_locked, group);
}
}
struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment