[Spice-devel] [spice-gtk] gtk-session: do not sync modifiers when focused

Victor Toso victortoso at redhat.com
Tue Apr 9 08:12:25 UTC 2019


From: Olivier Fourdan <ofourdan at redhat.com>

Spice gtk-session would try to synchronize the modifiers state whenever
the keymap changes, but doing so is inherently racy.

While the there is a keyboard grab in effect, all key events are
forwarded to the guest, hence all modifiers key press get processed by
the kernel on the guest.

Trying to synchronize the modifiers will generate additional key press/
release events which will result in the opposite effect and effectively
desynchronize the modifier states in the guest.

Synchronizing modifiers from the host should therefore be limited to
focus change, as actual press/release events might have occurred without
the guest knowing. Otherwise, no need to synchronize the modifiers.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---

Merge request spice-gtk!6 or
    https://gitlab.freedesktop.org/spice/spice-gtk/merge_requests/6

 src/spice-gtk-session.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index b48f92a..65442b2 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -163,6 +163,13 @@ static void keymap_modifiers_changed(GdkKeymap *keymap, gpointer data)
 {
     SpiceGtkSession *self = data;
 
+    /* set_key_locks() is inherently racy, but no need to sync modifiers
+     * if we have focus as the regular keypress/keyrelease will have set
+     * the expected modifiers state in the guest.
+     */
+    if (self->priv->keyboard_has_focus)
+      return;
+
     spice_gtk_session_sync_keyboard_modifiers(self);
 }
 
-- 
2.20.1



More information about the Spice-devel mailing list