From 847f0f33c74666268d783f4102f5de8b07f89600 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 1 Jun 2023 21:03:07 -0400 Subject: patch: unlock-screen (custom version) 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. --- slock.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/slock.c b/slock.c index aee377a..1a19d5f 100644 --- a/slock.c +++ b/slock.c @@ -232,7 +232,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; @@ -283,7 +283,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); @@ -327,11 +328,15 @@ main(int argc, char **argv) { Display *dpy; int s, nlocks, nscreens; CARD16 standby, suspend, off; + int unlock = 0; ARGBEGIN { case 'v': puts("slock-"VERSION); return 0; + case 'u': + unlock = 1; + break; default: usage(); } ARGEND @@ -376,7 +381,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; @@ -388,18 +393,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) { @@ -416,8 +423,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; } -- cgit v1.2.3