diff options
author | Malfurious <m@lfurio.us> | 2023-06-01 21:03:07 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-06-01 21:29:20 -0400 |
commit | 96ec08e24aa097ae5d09b45fe0bb9e3b7c67ce4b (patch) | |
tree | 676653e73a1eb0853a2018575b1c2862fcf98275 | |
parent | c6114c6dad641ea7e1dec230945023864fe1f6e7 (diff) | |
download | slock-master.tar.gz slock-master.zip |
This patch keeps the screen unlocked but keeps the input locked. That
is, the screen is not affected by slock, but users will not be able to
interact with the X session unless they enter the correct password.
This is a modified version of the patch from suckless.org which allows
the user to op-into this behavior with the -u command line option.
Additionally, it is written against the dpms patch, to disable its
effects when unlock-screen is active.
-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; } |