diff options
-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 |