diff options
-rw-r--r-- | slock.c | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -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 | ||
281 | static void | 283 | static void |