[Spice-devel] [PATCH v2 spice-gtk] Grab keyboard based on focus in windows client

Snir Sheriber ssheribe at redhat.com
Tue Jun 6 07:19:34 UTC 2017


Currently the client grabs keyboard based on session focus, on windows
environment gtk sends grab_broken if wm_killfocus is received (when
focus is changed) while the application has the grab. It means that
when grab is based on the session, clicking inside focusless window
will cause wm_killfocus to be sent towards the focused window, this
will generate grab_broken event which follows by no grab at all.

This patch expands the solution presented in 143ebfd to work also on
windows client without causing grab_broken event.
This is implemented a bit differently from linux, if on mouse entrance
session already has focus, focus will be set to the current window,
this will generate focus events that will release and take grab again
without grab_broken event.

Resolves: rhbz#1429611
Related: rhbz#1275231
---
Changes: Commit message bit more detailed now
---
 src/spice-widget.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/spice-widget.c b/src/spice-widget.c
index 1a1d5a6..b3407b5 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -850,10 +850,17 @@ static void try_keyboard_grab(SpiceDisplay *display)
         return;
     if (d->keyboard_grab_active)
         return;
+#ifdef G_OS_WIN32
+    if (!d->keyboard_have_focus)
+        return;
+    if (!d->mouse_have_pointer)
+        return;
+#else
     if (!spice_gtk_session_get_keyboard_has_focus(d->gtk_session))
         return;
     if (!spice_gtk_session_get_mouse_has_pointer(d->gtk_session))
         return;
+#endif
     if (d->keyboard_grab_released)
         return;
 
@@ -1543,6 +1550,12 @@ static void update_display(SpiceDisplay *display)
     win32_window = display ?
                         gdk_win32_window_get_impl_hwnd(gtk_widget_get_window(GTK_WIDGET(display))) :
                         NULL;
+    if(win32_window) {
+        SpiceDisplayPrivate *d = display->priv;
+        if(spice_gtk_session_get_keyboard_has_focus(d->gtk_session) &&
+           spice_gtk_session_get_mouse_has_pointer(d->gtk_session))
+            SetFocus(win32_window);
+    }
 #endif
 }
 
@@ -1862,7 +1875,6 @@ static gboolean focus_in_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_UN
 static gboolean focus_out_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_UNUSED)
 {
     SpiceDisplay *display = SPICE_DISPLAY(widget);
-    SpiceDisplayPrivate *d = display->priv;
 
     DISPLAY_DEBUG(display, "%s", __FUNCTION__);
     update_display(NULL);
@@ -1871,8 +1883,11 @@ static gboolean focus_out_event(GtkWidget *widget, GdkEventFocus *focus G_GNUC_U
      * Ignore focus out after a keyboard grab
      * (this happens when doing the grab from the enter_event callback).
      */
+#ifndef G_OS_WIN32
+    SpiceDisplayPrivate *d = display->priv;
     if (d->keyboard_grab_active)
         return true;
+#endif
 
     release_keys(display);
     update_keyboard_focus(display, false);
-- 
2.9.3



More information about the Spice-devel mailing list