summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-06-01 21:03:07 -0400
committerMatt Hunter <m@lfurio.us>2026-01-17 17:14:15 -0500
commit847f0f33c74666268d783f4102f5de8b07f89600 (patch)
tree6e9816e13bc8a873baf7320e6617e1408ae28fa0
parent18f363f122f4fe6001aaf301d7321a7867e8ed9e (diff)
downloadslock-847f0f33c74666268d783f4102f5de8b07f89600.tar.gz
slock-847f0f33c74666268d783f4102f5de8b07f89600.zip
patch: unlock-screen (custom version)HEADmaster
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.c43
1 files 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;
}