aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-01-18 16:49:15 +0100
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-01-18 16:49:15 +0100
commit9dfe0ce531023bf63c0e518b07ee97cf0cac742a (patch)
treeb6835c5f52f118f1a9f1ed4b6868fa3f9cf20814
parent55e827af0fb94f6c2b9e76a7bfe7e98cf697dc7b (diff)
error messages on grab failure
-rw-r--r--slock.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/slock.c b/slock.c
index d2c3729..df2d3c6 100644
--- a/slock.c
+++ b/slock.c
@@ -230,7 +230,7 @@ lockscreen(Display *dpy, int screen)
230 XSetWindowAttributes wa; 230 XSetWindowAttributes wa;
231 Cursor invisible; 231 Cursor invisible;
232 232
233 if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(Lock)))) 233 if (!running || dpy == NULL || screen < 0 || !(lock = malloc(sizeof(Lock))))
234 return NULL; 234 return NULL;
235 235
236 lock->screen = screen; 236 lock->screen = screen;
@@ -253,29 +253,31 @@ lockscreen(Display *dpy, int screen)
253 XMapRaised(dpy, lock->win); 253 XMapRaised(dpy, lock->win);
254 if (rr) 254 if (rr)
255 XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); 255 XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
256
257 /* Try to grab mouse pointer *and* keyboard, else fail the lock */
256 for (len = 1000; len; len--) { 258 for (len = 1000; len; len--) {
257 if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, 259 if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
258 GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) 260 GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
259 break; 261 break;
260 usleep(1000); 262 usleep(1000);
261 } 263 }
262 if (running && len) { 264 if (!len) {
265 fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen);
266 } else {
263 for (len = 1000; len; len--) { 267 for (len = 1000; len; len--) {
264 if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) 268 if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) {
265 break; 269 /* everything fine, we grabbed both inputs */
270 XSelectInput(dpy, lock->root, SubstructureNotifyMask);
271 return lock;
272 }
266 usleep(1000); 273 usleep(1000);
267 } 274 }
275 fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen);
268 } 276 }
269 277 /* grabbing one of the inputs failed */
270 running &= (len > 0); 278 running = 0;
271 if (!running) { 279 unlockscreen(dpy, lock);
272 unlockscreen(dpy, lock); 280 return NULL;
273 lock = NULL;
274 } else {
275 XSelectInput(dpy, lock->root, SubstructureNotifyMask);
276 }
277
278 return lock;
279} 281}
280 282
281static void 283static void