From 96ec08e24aa097ae5d09b45fe0bb9e3b7c67ce4b 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 8393fd2..17189c7 100644 --- a/slock.c +++ b/slock.c @@ -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; } -- cgit v1.2.3