[Spice-commits] src/spice-widget.c

Victor Toso de Carvalho victortoso at kemper.freedesktop.org
Thu Jun 15 14:22:03 UTC 2017


 src/spice-widget.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

New commits:
commit 178fe41e9fb8a50b72155becdd367820c88ef177
Author: Snir Sheriber <ssheribe at redhat.com>
Date:   Tue Jun 6 10:19:34 2017 +0300

    Grab keyboard based on focus in windows client
    
    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
    
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/src/spice-widget.c b/src/spice-widget.c
index 0945ac6..386724d 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -851,10 +851,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;
 
@@ -1544,6 +1551,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
 }
 
@@ -1863,7 +1876,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);
@@ -1872,8 +1884,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);


More information about the Spice-commits mailing list