[Xfce4-commits] [apps/xfce4-screensaver] 01/01: Fix password entry after stealing focus (bug #15042)

noreply at xfce.org noreply at xfce.org
Sun Mar 17 12:23:52 CET 2019


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-screensaver.

commit 20df0e3b2d5aba5781be89a2c905c8c2094123cd
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Sun Mar 17 07:23:43 2019 -0400

    Fix password entry after stealing focus (bug #15042)
---
 NEWS              |  2 ++
 src/gs-grab-x11.c | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 39cc1cc..755d3e4 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@
 ==================
 - Features:
   - Added support for locking on suspend (Xfce #15001)
+- Bug Fixes:
+  - Fix password entry after stealing focus (Xfce #15042)
 - General:
   - Faster screen locking when activated
   - Faster renderering of the authentication prompt
diff --git a/src/gs-grab-x11.c b/src/gs-grab-x11.c
index 6d75031..8b70932 100644
--- a/src/gs-grab-x11.c
+++ b/src/gs-grab-x11.c
@@ -330,13 +330,26 @@ gs_grab_nuke_focus (GdkDisplay *display) {
     gdk_x11_display_error_trap_pop_ignored (display);
 }
 
+static void
+gs_grab_restore_focus (GdkDisplay *display, GdkWindow *window) {
+    gs_debug ("Restoring focus");
+
+    gdk_x11_display_error_trap_push (display);
+
+    XSetInputFocus (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
+                    RevertToParent, CurrentTime);
+
+    gdk_x11_display_error_trap_pop_ignored (display);
+}
+
 gboolean
 gs_grab_grab_window (GSGrab     *grab,
                      GdkWindow  *window,
                      GdkDisplay *display,
                      gboolean    no_pointer_grab,
                      gboolean    hide_cursor) {
-    gboolean    status = FALSE;
+    gint        status = FALSE;
+    gboolean    nuked = FALSE;
     int         i;
     int         retries = 12;
 
@@ -348,12 +361,31 @@ gs_grab_grab_window (GSGrab     *grab,
         } else if (i == (int) (retries / 2)) {
             /* try nuking focus in the middle */
             gs_grab_nuke_focus (display);
+            nuked = TRUE;
         }
 
         /* else, wait a second and try to grab again */
         g_usleep (SLEEPTIMEOUT);
     }
 
+    /* Something else has grab. Begin aggressive grab cycle. */
+    while (status == GDK_GRAB_ALREADY_GRABBED) {
+        for (i = 0; i < retries; i++) {
+            status = gs_grab_get (grab, window, display,
+                                no_pointer_grab, hide_cursor);
+            if (status == GDK_GRAB_SUCCESS) {
+                break;
+            } else if (i == (int) (retries / 2)) {
+                /* try nuking focus in the middle */
+                gs_grab_nuke_focus (display);
+                nuked = TRUE;
+            }
+
+            /* else, wait a second and try to grab again */
+            g_usleep (SLEEPTIMEOUT);
+        }
+    }
+
     if (status != GDK_GRAB_SUCCESS) {
         gs_debug ("Couldn't grab devices!  (%s)",
                   grab_string (status));
@@ -362,6 +394,10 @@ gs_grab_grab_window (GSGrab     *grab,
         return FALSE;
     }
 
+    if (nuked) {
+        gs_grab_restore_focus (display, window);
+    }
+
     /* grab is good, go ahead and blank  */
     return TRUE;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list