[Spice-devel,spice-gtk,2/6] spice-gtk-session: Fix keyboard focus tracking

Submitted by Hans de Goede on June 26, 2012, 11:49 a.m.

Details

Message ID 1340711344-19529-3-git-send-email-hdegoede@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Hans de Goede June 26, 2012, 11:49 a.m.
This patch changes the "do we have focus?" tracking, to keeping a counter with
how many widgets have focus. The reason for this is that sometimes multiple
spice-widgets can have focus at the same time, yes really! Sometimes (rarely,
hard to reproduce) the focus in event for one window arrives before the
focus out of the other window.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 gtk/spice-gtk-session.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
index 130cbc9..1d8c888 100644
--- a/gtk/spice-gtk-session.c
+++ b/gtk/spice-gtk-session.c
@@ -39,7 +39,7 @@  struct _SpiceGtkSessionPrivate {
     gboolean                clipboard_by_guest[CLIPBOARD_LAST];
     /* auto-usbredir related */
     gboolean                auto_usbredir_enable;
-    gboolean                keyboard_focus;
+    int                     keyboard_focus;
 };
 
 /**
@@ -845,7 +845,16 @@  void spice_gtk_session_update_keyboard_focus(SpiceGtkSession *self,
     SpiceGtkSessionPrivate *s = self->priv;
     SpiceUsbDeviceManager *manager;
 
-    s->keyboard_focus = state;
+    if (state) {
+        s->keyboard_focus++;
+        if (s->keyboard_focus != 1)
+            return;
+    } else {
+        g_return_if_fail(s->keyboard_focus > 0);
+        s->keyboard_focus--;
+        if (s->keyboard_focus != 0)
+            return;
+    }
 
     if (!s->auto_usbredir_enable)
         return;