- XMapRaised(dpy, lock->win);
- if (rr)
- XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
- for (len = 1000; len; len--) {
- if (XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
- GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
- break;
- usleep(1000);
- }
- if (running && len) {
- for (len = 1000; len; len--) {
- if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
- break;
- usleep(1000);
- }
+
+ /* Try to grab mouse pointer *and* keyboard, else fail the lock */
+ if (XGrabPointer(dpy, lock->root, False, ButtonPressMask |
+ ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync,
+ None, invisible, CurrentTime) != GrabSuccess) {
+ fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen);
+ running = 0;
+ unlockscreen(dpy, lock);
+ return NULL;