diff options
author | eplanet <emeric.planet@gmail.com> | 2016-09-28 03:39:52 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2016-09-27 18:39:52 -0700 |
commit | 1c97a8484723b7db6c96c3b7bfa4c86c26f47b5a (patch) | |
tree | 0b25192dc3cd1d9fb0151d58174755292cd891f5 /xcb.c | |
parent | fd2215b0f08991f0f710533b122a182438ff2237 (diff) |
Displaying locking message when grabbing the pointer/keyboard. (#88)
Display "locking…" message when grabbing the pointer/keyboard,
after at least 250 ms of unfruitful attempts. If grabbing
eventually fails, application will not fork and return 1.
Diffstat (limited to 'xcb.c')
-rw-r--r-- | xcb.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -18,8 +18,10 @@ #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) |