[spice-gtk PATCH v5] Grab keyboard based on session focus.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When using multiple monitors moving mouse between monitors releases
keyboard grab.

Reproduce bug
-Open multiple monitors remote-viewer session
-Click on one of the monitors to get focus & keyboard-grab
-Move mouse to another monitor and try keyboard command (do not click)
At this point all keyboard commands are being executed on the client
machine instead of the remote machine

I added keyboard_has_focus and mouse_has_pointer variables at the
session and now these properties are being tested for the session
instead for the current widget (works also when using alt-tab).

Resolves: rhbz#1275231
---
No GObject properties were set
---
---
 src/spice-gtk-session-priv.h |  4 ++++
 src/spice-gtk-session.c      | 35 +++++++++++++++++++++++++++++++++++
 src/spice-widget.c           |  7 +++++--
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/src/spice-gtk-session-priv.h b/src/spice-gtk-session-priv.h
index 91304b2..b2b6206 100644
--- a/src/spice-gtk-session-priv.h
+++ b/src/spice-gtk-session-priv.h
@@ -28,6 +28,10 @@ gboolean spice_gtk_session_get_read_only(SpiceGtkSession *self);
 void spice_gtk_session_sync_keyboard_modifiers(SpiceGtkSession *self);
 void spice_gtk_session_set_pointer_grabbed(SpiceGtkSession *self, gboolean grabbed);
 gboolean spice_gtk_session_get_pointer_grabbed(SpiceGtkSession *self);
+void spice_gtk_session_set_keyboard_has_focus(SpiceGtkSession *self, gboolean keyboard_has_focus);
+void spice_gtk_session_set_mouse_has_pointer(SpiceGtkSession *self, gboolean  mouse_has_pointer);
+gboolean spice_gtk_session_get_keyboard_has_focus(SpiceGtkSession *self);
+gboolean spice_gtk_session_get_mouse_has_pointer(SpiceGtkSession *self);
 
 G_END_DECLS
 
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 5abb16c..9ea28c4 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -64,6 +64,8 @@ struct _SpiceGtkSessionPrivate {
     gboolean                auto_usbredir_enable;
     int                     auto_usbredir_reqs;
     gboolean                pointer_grabbed;
+    gboolean                keyboard_has_focus;
+    gboolean                mouse_has_pointer;
 };
 
 /**
@@ -1227,3 +1229,36 @@ gboolean spice_gtk_session_get_pointer_grabbed(SpiceGtkSession *self)
 
     return self->priv->pointer_grabbed;
 }
+
+G_GNUC_INTERNAL
+void spice_gtk_session_set_keyboard_has_focus(SpiceGtkSession *self,
+                                                gboolean keyboard_has_focus)
+{
+    g_return_if_fail(SPICE_IS_GTK_SESSION(self));
+
+    self->priv->keyboard_has_focus = keyboard_has_focus;
+}
+
+G_GNUC_INTERNAL
+void spice_gtk_session_set_mouse_has_pointer(SpiceGtkSession *self,
+                                                gboolean mouse_has_pointer)
+{
+   g_return_if_fail(SPICE_IS_GTK_SESSION(self));
+   self->priv->mouse_has_pointer = mouse_has_pointer;
+}
+
+G_GNUC_INTERNAL
+gboolean spice_gtk_session_get_keyboard_has_focus(SpiceGtkSession *self)
+{
+    g_return_val_if_fail(SPICE_IS_GTK_SESSION(self), FALSE);
+
+    return self->priv->keyboard_has_focus;
+}
+
+G_GNUC_INTERNAL
+gboolean spice_gtk_session_get_mouse_has_pointer(SpiceGtkSession *self)
+{
+    g_return_val_if_fail(SPICE_IS_GTK_SESSION(self), FALSE);
+
+    return self->priv->mouse_has_pointer;
+}
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 503f82a..614d93e 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -208,6 +208,7 @@ static void update_keyboard_focus(SpiceDisplay *display, gboolean state)
     SpiceDisplayPrivate *d = display->priv;
 
     d->keyboard_have_focus = state;
+    spice_gtk_session_set_keyboard_has_focus(d->gtk_session, state);
 
     /* keyboard grab gets inhibited by usb-device-manager when it is
        in the process of redirecting a usb-device (as this may show a
@@ -737,9 +738,9 @@ static void try_keyboard_grab(SpiceDisplay *display)
         return;
     if (d->keyboard_grab_active)
         return;
-    if (!d->keyboard_have_focus)
+    if (!spice_gtk_session_get_keyboard_has_focus(d->gtk_session))
         return;
-    if (!d->mouse_have_pointer)
+    if (!spice_gtk_session_get_mouse_has_pointer(d->gtk_session))
         return;
     if (d->keyboard_grab_released)
         return;
@@ -1465,6 +1466,7 @@ static gboolean enter_event(GtkWidget *widget, GdkEventCrossing *crossing G_GNUC
     SPICE_DEBUG("%s", __FUNCTION__);
 
     d->mouse_have_pointer = true;
+    spice_gtk_session_set_mouse_has_pointer(d->gtk_session, true);
     try_keyboard_grab(display);
     update_display(display);
 
@@ -1482,6 +1484,7 @@ static gboolean leave_event(GtkWidget *widget, GdkEventCrossing *crossing G_GNUC
         return true;
 
     d->mouse_have_pointer = false;
+    spice_gtk_session_set_mouse_has_pointer(d->gtk_session, false);
     try_keyboard_ungrab(display);
 
     return true;
-- 
2.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]