diff options
-rw-r--r-- | slock.c | 43 |
1 files changed, 26 insertions, 17 deletions
@@ -231,7 +231,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, } static struct lock * -lockscreen(Display *dpy, struct xrandr *rr, int screen) +lockscreen(Display *dpy, struct xrandr *rr, int screen, int unlock) { char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; int i, ptgrab, kbgrab; @@ -282,7 +282,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) /* input is grabbed: we can lock the screen */ if (ptgrab == GrabSuccess && kbgrab == GrabSuccess) { - XMapRaised(dpy, lock->win); + if (!unlock) + XMapRaised(dpy, lock->win); if (rr->active) XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); @@ -326,11 +327,15 @@ main(int argc, char **argv) { Display *dpy; int s, nlocks, nscreens; CARD16 standby, suspend, off; + int unlock = 0; ARGBEGIN { case 'v': fprintf(stderr, "slock-"VERSION"\n"); return 0; + case 'u': + unlock = 1; + break; default: usage(); } ARGEND @@ -375,7 +380,7 @@ main(int argc, char **argv) { if (!(locks = calloc(nscreens, sizeof(struct lock *)))) die("slock: out of memory\n"); for (nlocks = 0, s = 0; s < nscreens; s++) { - if ((locks[s] = lockscreen(dpy, &rr, s)) != NULL) + if ((locks[s] = lockscreen(dpy, &rr, s, unlock)) != NULL) nlocks++; else break; @@ -387,18 +392,20 @@ main(int argc, char **argv) { return 1; /* DPMS magic to disable the monitor */ - if (!DPMSCapable(dpy)) - die("slock: DPMSCapable failed\n"); - if (!DPMSEnable(dpy)) - die("slock: DPMSEnable failed\n"); - if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off)) - die("slock: DPMSGetTimeouts failed\n"); - //if (!standby || !suspend || !off) - //die("slock: at least one DPMS variable is zero\n"); - if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime)) - die("slock: DPMSSetTimeouts failed\n"); - - XSync(dpy, 0); + if (!unlock) { + if (!DPMSCapable(dpy)) + die("slock: DPMSCapable failed\n"); + if (!DPMSEnable(dpy)) + die("slock: DPMSEnable failed\n"); + if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off)) + die("slock: DPMSGetTimeouts failed\n"); + //if (!standby || !suspend || !off) + //die("slock: at least one DPMS variable is zero\n"); + if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime)) + die("slock: DPMSSetTimeouts failed\n"); + + XSync(dpy, 0); + } /* run post-lock command */ if (argc > 0) { @@ -418,8 +425,10 @@ main(int argc, char **argv) { readpw(dpy, &rr, locks, nscreens, hash); /* reset DPMS values to inital ones */ - DPMSSetTimeouts(dpy, standby, suspend, off); - XSync(dpy, 0); + if (!unlock) { + DPMSSetTimeouts(dpy, standby, suspend, off); + XSync(dpy, 0); + } return 0; } |