diff options
author | Quentin Rameau <quinq@fifth.space> | 2016-08-30 17:33:09 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-30 19:54:26 +0200 |
commit | c2f975773d720e734dbdab9a1e9ae51b0972ae0c (patch) | |
tree | 1f7836c5fd6ee498756fdf3fe2d78b732e04ba28 | |
parent | 3bb868e40873c568acdec74f7783c77f063aa396 (diff) |
Exit as soon as possible on input grabbing error
We want to know at once if slock failed or not to lock the screen, not
seing a black screen for a whole second (or two) and then die.
Thanks to ^7heo for reporting this.
-rw-r--r-- | slock.c | 44 |
1 files changed, 20 insertions, 24 deletions
@@ -222,7 +222,6 @@ static Lock * | |||
222 | lockscreen(Display *dpy, int screen) | 222 | lockscreen(Display *dpy, int screen) |
223 | { | 223 | { |
224 | char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; | 224 | char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; |
225 | unsigned int len; | ||
226 | int i; | 225 | int i; |
227 | Lock *lock; | 226 | Lock *lock; |
228 | XColor color, dummy; | 227 | XColor color, dummy; |
@@ -249,34 +248,31 @@ lockscreen(Display *dpy, int screen) | |||
249 | lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); | 248 | lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); |
250 | invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0); | 249 | invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0); |
251 | XDefineCursor(dpy, lock->win, invisible); | 250 | XDefineCursor(dpy, lock->win, invisible); |
252 | XMapRaised(dpy, lock->win); | ||
253 | if (rr) | ||
254 | XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); | ||
255 | 251 | ||
256 | /* Try to grab mouse pointer *and* keyboard, else fail the lock */ | 252 | /* Try to grab mouse pointer *and* keyboard, else fail the lock */ |
257 | for (len = 1000; len; len--) { | 253 | if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | |
258 | if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, | 254 | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, |
259 | GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) | 255 | None, invisible, CurrentTime) != GrabSuccess) { |
260 | break; | ||
261 | usleep(1000); | ||
262 | } | ||
263 | if (!len) { | ||
264 | fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); | 256 | fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); |
265 | } else { | 257 | running = 0; |
266 | for (len = 1000; len; len--) { | 258 | unlockscreen(dpy, lock); |
267 | if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) { | 259 | return NULL; |
268 | /* everything fine, we grabbed both inputs */ | 260 | } |
269 | XSelectInput(dpy, lock->root, SubstructureNotifyMask); | 261 | |
270 | return lock; | 262 | if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, |
271 | } | 263 | CurrentTime) != GrabSuccess) { |
272 | usleep(1000); | ||
273 | } | ||
274 | fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); | 264 | fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); |
265 | running = 0; | ||
266 | unlockscreen(dpy, lock); | ||
267 | return NULL; | ||
275 | } | 268 | } |
276 | /* grabbing one of the inputs failed */ | 269 | |
277 | running = 0; | 270 | XMapRaised(dpy, lock->win); |
278 | unlockscreen(dpy, lock); | 271 | if (rr) |
279 | return NULL; | 272 | XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); |
273 | |||
274 | XSelectInput(dpy, lock->root, SubstructureNotifyMask); | ||
275 | return lock; | ||
280 | } | 276 | } |
281 | 277 | ||
282 | static void | 278 | static void |