[PATCH xserver 2/2] xwayland: add a server sync before repeating keys

Olivier Fourdan ofourdan at redhat.com
Mon Mar 7 17:45:01 UTC 2016


Key repeat is handled by the X server, but input events need to be
processed and forwarded by the Wayland compositor first.

Make sure the Wayland compositor is actually processing events, to
avoid repeating keys in xwayland while the Wayland compositor cannot
deal with input events for whatever reason, thus not dispatching key
release events, leading to fictious repeat keys while the use has
already released the key.

Bugzilla: https://bugzilla.gnome.org/show_bug.cgi?id=762618
Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---
 hw/xwayland/xwayland-input.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index f9e3255..ca60505 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -527,6 +527,41 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
 }
 
 static void
+sync_callback(void *data, struct wl_callback *callback, uint32_t serial)
+{
+    Bool *sync_pending = (Bool *) data;
+
+    *sync_pending = FALSE;
+    wl_callback_destroy(callback);
+}
+
+static const struct wl_callback_listener sync_listener = {
+   sync_callback
+};
+
+static Bool
+keyboard_check_repeat (DeviceIntPtr dev, XkbSrvInfoPtr xkbi, unsigned key)
+{
+    static Bool sync_pending;
+    struct xwl_seat *xwl_seat = dev->public.devicePrivate;
+    struct xwl_screen *xwl_screen = xwl_seat->xwl_screen;
+    struct wl_callback *callback;
+
+    if (!sync_pending) {
+        callback = wl_display_sync (xwl_screen->display);
+        wl_callback_add_listener(callback, &sync_listener, &sync_pending);
+        sync_pending = TRUE;
+
+        return TRUE;
+    }
+
+    ErrorF("Key repeat discarded, Wayland compositor doesn't seem to "
+           "be processing events fast enough!\n");
+
+    return FALSE;
+}
+
+static void
 keyboard_handle_repeat_info (void *data, struct wl_keyboard *keyboard,
                              int32_t rate, int32_t delay)
 {
@@ -551,6 +586,7 @@ keyboard_handle_repeat_info (void *data, struct wl_keyboard *keyboard,
             ctrl->repeat_interval = 1000 / rate;
 
 	    XkbSetRepeatKeys(dev, -1, AutoRepeatModeOn);
+            dev->key->xkbInfo->checkRepeat = keyboard_check_repeat;
 	} else
 	    XkbSetRepeatKeys(dev, -1, AutoRepeatModeOff);
     }
-- 
2.5.0



More information about the xorg-devel mailing list