]> 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 6731137f2e4070880a1a581ddd9873830c07fcce..92c78469c664a5e1c0819f4bb4d6fa815112af81 100644 (file)
--- a/xcb.c
+++ b/xcb.c
@@ -1,7 +1,7 @@
 /*
  * vim:ts=4:sw=4:expandtab
  *
- * © 2010-2012 Michael Stapelberg
+ * © 2010 Michael Stapelberg
  *
  * xcb.c: contains all functions which use XCB to talk to X11. Mostly wrappers
  *        around the rather complicated/ugly parts of the XCB API.
@@ -10,7 +10,7 @@
 #include <xcb/xcb.h>
 #include <xcb/xcb_image.h>
 #include <xcb/xcb_atom.h>
-#include <xcb/dpms.h>
+#include <xcb/xcb_aux.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #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;
@@ -151,17 +153,10 @@ xcb_window_t open_fullscreen_window(xcb_connection_t *conn, xcb_screen_t *scr, c
     values[0] = XCB_STACK_MODE_ABOVE;
     xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
 
-    return win;
-}
+    /* Ensure that the window is created and set up before returning */
+    xcb_aux_sync(conn);
 
-/*
- * Set the dpms level to 'mode'.
- *
- */
-void dpms_set_mode(xcb_connection_t *conn, xcb_dpms_dpms_mode_t mode) {
-    xcb_dpms_enable(conn);
-    xcb_dpms_force_level(conn, mode);
-    xcb_flush(conn);
+    return win;
 }
 
 /*
@@ -177,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,
@@ -197,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) {
@@ -216,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)