libweston: Send wl_keyboard.modifiers after wl_keyboard.enter
authorKirill Chibisov <contact@kchibisov.com>
Tue, 16 Jun 2020 22:43:57 +0000 (01:43 +0300)
committerKirill Chibisov <contact@kchibisov.com>
Thu, 9 Jul 2020 14:47:11 +0000 (17:47 +0300)
The core Wayland protocol explicitly states that wl_keyboard.modifiers
must be send after wl_keyboard.enter.

This commit also changes the behavior of `seat_get_keyboard` to not
send `wl_keyboard.modifiers` in case where seat had pointer focus,
but not keyboard one.

Signed-off-by: Kirill Chibisov <contact@kchibisov.com>
libweston/input.c

index e348a56b911a19d062ad7a2709a2d07ec980ba75..b4e2c66fa66e36d8be23a5e31df502af606eb0b4 100644 (file)
@@ -1518,10 +1518,10 @@ send_enter_to_resource_list(struct wl_list *list,
        struct wl_resource *resource;
 
        wl_resource_for_each(resource, list) {
-               send_modifiers_to_resource(keyboard, resource, serial);
                wl_keyboard_send_enter(resource, serial,
                                       surface->resource,
                                       &keyboard->keys);
+               send_modifiers_to_resource(keyboard, resource, serial);
        }
 }
 
@@ -2848,28 +2848,6 @@ static const struct wl_keyboard_interface keyboard_interface = {
        keyboard_release
 };
 
-static bool
-should_send_modifiers_to_client(struct weston_seat *seat,
-                               struct wl_client *client)
-{
-       struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
-       struct weston_pointer *pointer = weston_seat_get_pointer(seat);
-
-       if (keyboard &&
-           keyboard->focus &&
-           keyboard->focus->resource &&
-           wl_resource_get_client(keyboard->focus->resource) == client)
-               return true;
-
-       if (pointer &&
-           pointer->focus &&
-           pointer->focus->surface->resource &&
-           wl_resource_get_client(pointer->focus->surface->resource) == client)
-               return true;
-
-       return false;
-}
-
 static void
 seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
                  uint32_t id)
@@ -2915,12 +2893,6 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
 
        weston_keyboard_send_keymap(keyboard, cr);
 
-       if (should_send_modifiers_to_client(seat, client)) {
-               send_modifiers_to_resource(keyboard,
-                                          cr,
-                                          keyboard->focus_serial);
-       }
-
        if (keyboard->focus && keyboard->focus->resource &&
            wl_resource_get_client(keyboard->focus->resource) == client) {
                struct weston_surface *surface =
@@ -2934,6 +2906,10 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
                                       surface->resource,
                                       &keyboard->keys);
 
+               send_modifiers_to_resource(keyboard,
+                                          cr,
+                                          keyboard->focus_serial);
+
                /* If this is the first keyboard resource for this
                 * client... */
                if (keyboard->focus_resource_list.prev ==