diff options
| author | Malfurious <m@lfurio.us> | 2023-06-01 16:22:33 -0400 |
|---|---|---|
| committer | Matt Hunter <m@lfurio.us> | 2026-01-17 17:10:59 -0500 |
| commit | 18f363f122f4fe6001aaf301d7321a7867e8ed9e (patch) | |
| tree | 9c2a572ebeb4a7b886fa9ac94dfc7eac116f0668 | |
| parent | 813a093e6c3c66b61020a4a855c83a236c4cdd7c (diff) | |
| download | slock-18f363f122f4fe6001aaf301d7321a7867e8ed9e.tar.gz slock-18f363f122f4fe6001aaf301d7321a7867e8ed9e.zip | |
patch: dpms
This patch interacts with the Display Power Management Signaling and
automatically turns off the monitor after a configurable time. The
monitor is reactivated by a keystroke or moving the mouse.
The time until the monitor is disabled is configurable as monitortime in
the config.h file in seconds.
This is a modified version of the patch from suckless.org which permits
normal timeout values of zero.
| -rw-r--r-- | config.def.h | 3 | ||||
| -rw-r--r-- | slock.c | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index 3639e91..3420af9 100644 --- a/config.def.h +++ b/config.def.h @@ -14,3 +14,6 @@ static const int failonclear = 1; /* allow control key to trigger fail on clear */ static const int controlkeyclear = 1; + +/* time in seconds before the monitor shuts down */ +static const int monitortime = 7; @@ -16,6 +16,7 @@ #include <spawn.h> #include <sys/types.h> #include <X11/extensions/Xrandr.h> +#include <X11/extensions/dpms.h> #include <X11/keysym.h> #include <X11/Xlib.h> #include <X11/Xutil.h> @@ -325,6 +326,7 @@ main(int argc, char **argv) { const char *hash; Display *dpy; int s, nlocks, nscreens; + CARD16 standby, suspend, off; ARGBEGIN { case 'v': @@ -385,6 +387,20 @@ main(int argc, char **argv) { if (nlocks != nscreens) 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); + /* run post-lock command */ if (argc > 0) { pid_t pid; @@ -399,5 +415,9 @@ main(int argc, char **argv) { /* everything is now blank. Wait for the correct password */ readpw(dpy, &rr, locks, nscreens, hash); + /* reset DPMS values to inital ones */ + DPMSSetTimeouts(dpy, standby, suspend, off); + XSync(dpy, 0); + return 0; } |
