diff options
-rw-r--r-- | slock.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -234,6 +234,11 @@ unlockscreen(Display *dpy, Lock *lock) | |||
234 | static void | 234 | static void |
235 | cleanup(Display *dpy) | 235 | cleanup(Display *dpy) |
236 | { | 236 | { |
237 | int s; | ||
238 | |||
239 | for (s = 0; s < nscreens; ++s) | ||
240 | unlockscreen(dpy, locks[s]); | ||
241 | |||
237 | free(locks); | 242 | free(locks); |
238 | XCloseDisplay(dpy); | 243 | XCloseDisplay(dpy); |
239 | } | 244 | } |
@@ -305,8 +310,6 @@ lockscreen(Display *dpy, int screen) | |||
305 | fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); | 310 | fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); |
306 | if (kbgrab != GrabSuccess) | 311 | if (kbgrab != GrabSuccess) |
307 | fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); | 312 | fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); |
308 | running = 0; | ||
309 | unlockscreen(dpy, lock); | ||
310 | return NULL; | 313 | return NULL; |
311 | } | 314 | } |
312 | 315 | ||
@@ -359,19 +362,21 @@ main(int argc, char **argv) { | |||
359 | 362 | ||
360 | /* get number of screens in display "dpy" and blank them */ | 363 | /* get number of screens in display "dpy" and blank them */ |
361 | nscreens = ScreenCount(dpy); | 364 | nscreens = ScreenCount(dpy); |
362 | if (!(locks = malloc(sizeof(Lock *) * nscreens))) { | 365 | if (!(locks = calloc(nscreens, sizeof(Lock *)))) { |
363 | XCloseDisplay(dpy); | 366 | XCloseDisplay(dpy); |
364 | die("slock: out of memory\n"); | 367 | die("slock: out of memory\n"); |
365 | } | 368 | } |
366 | for (nlocks = 0, s = 0; s < nscreens; s++) { | 369 | for (nlocks = 0, s = 0; s < nscreens; s++) { |
367 | if ((locks[s] = lockscreen(dpy, s)) != NULL) | 370 | if ((locks[s] = lockscreen(dpy, s)) != NULL) |
368 | nlocks++; | 371 | nlocks++; |
372 | else | ||
373 | break; | ||
369 | } | 374 | } |
370 | XSync(dpy, 0); | 375 | XSync(dpy, 0); |
371 | 376 | ||
372 | /* did we actually manage to lock anything? */ | 377 | /* did we manage to lock everything? */ |
373 | if (nlocks == 0) { | 378 | if (nlocks != nscreens) { |
374 | /* nothing to protect */ | 379 | running = 0; |
375 | cleanup(dpy); | 380 | cleanup(dpy); |
376 | return 1; | 381 | return 1; |
377 | } | 382 | } |
@@ -400,9 +405,6 @@ main(int argc, char **argv) { | |||
400 | #endif | 405 | #endif |
401 | 406 | ||
402 | /* password ok, unlock everything and quit */ | 407 | /* password ok, unlock everything and quit */ |
403 | for (s = 0; s < nscreens; s++) | ||
404 | unlockscreen(dpy, locks[s]); | ||
405 | |||
406 | cleanup(dpy); | 408 | cleanup(dpy); |
407 | 409 | ||
408 | return 0; | 410 | return 0; |