]> git.sur5r.net Git - i3/i3lock/blobdiff - xcb.c
Displaying locking message when grabbing the pointer/keyboard. (#88)
[i3/i3lock] / xcb.c
diff --git a/xcb.c b/xcb.c
index 3e8cd071c455954b1189fed6e4392ce3338f7140..92c78469c664a5e1c0819f4bb4d6fa815112af81 100644 (file)
--- a/xcb.c
+++ b/xcb.c
 #include <unistd.h>
 #include <assert.h>
 #include <err.h>
+#include <time.h>
 
 #include "cursors.h"
+#include "unlock_indicator.h"
 
 xcb_connection_t *conn;
 xcb_screen_t *screen;
@@ -170,6 +172,10 @@ void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb
 
     int tries = 10000;
 
+    /* Using few variables to trigger a redraw_screen() if too many tries */
+    bool redrawn = false;
+    time_t start = clock();
+
     while (tries-- > 0) {
         pcookie = xcb_grab_pointer(
             conn,
@@ -190,6 +196,14 @@ void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb
 
         /* Make this quite a bit slower */
         usleep(50);
+
+        /* Measure elapsed time and trigger a screen redraw if elapsed > 250000 */
+        if (!redrawn &&
+            (tries % 100) == 0 &&
+            (clock() - start) > 250000) {
+            redraw_screen();
+            redrawn = true;
+        }
     }
 
     while (tries-- > 0) {
@@ -209,6 +223,14 @@ void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb
 
         /* Make this quite a bit slower */
         usleep(50);
+
+        /* Measure elapsed time and trigger a screen redraw if elapsed > 250000 */
+        if (!redrawn &&
+            (tries % 100) == 0 &&
+            (clock() - start) > 250000) {
+            redraw_screen();
+            redrawn = true;
+        }
     }
 
     if (tries <= 0)