diff options
author | Malfurious <m@lfurio.us> | 2023-06-01 16:22:33 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-06-01 21:26:22 -0400 |
commit | c6114c6dad641ea7e1dec230945023864fe1f6e7 (patch) | |
tree | 9358b8cf32bad0a7cd02b0eae59b337b1cfbb7a1 /slock.c | |
parent | 80ba53531670f06b82a6592e878ed7e7a802b4e6 (diff) | |
download | slock-c6114c6dad641ea7e1dec230945023864fe1f6e7.tar.gz slock-c6114c6dad641ea7e1dec230945023864fe1f6e7.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.
Diffstat (limited to 'slock.c')
-rw-r--r-- | slock.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -15,6 +15,7 @@ #include <unistd.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> @@ -324,6 +325,7 @@ main(int argc, char **argv) { const char *hash; Display *dpy; int s, nlocks, nscreens; + CARD16 standby, suspend, off; ARGBEGIN { case 'v': @@ -384,6 +386,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) { switch (fork()) { @@ -401,5 +417,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; } |