From 81508c653879088035bf0b6fc51e76d1d83c962c Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 20 Sep 2023 17:42:27 -0400 Subject: [PATCH] apply dpms patch Turns the monitor off after some time. --- config.def.h | 3 +++ slock.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/config.def.h b/config.def.h index 25ce538..8ade6ea 100644 --- a/config.def.h +++ b/config.def.h @@ -36,3 +36,6 @@ static const int blurRadius=5; //#define PIXELATION /*Set pixelation radius*/ static const int pixelSize=0; + +/* time in seconds before the monitor shuts down */ +static const int monitortime = 5; diff --git a/slock.c b/slock.c index 5ba6c2c..07715d8 100644 --- a/slock.c +++ b/slock.c @@ -19,6 +19,7 @@ #ifdef XINERAMA #include #endif +#include #include #include #include @@ -392,6 +393,7 @@ main(int argc, char **argv) { const char *hash; Display *dpy; int s, nlocks, nscreens; + CARD16 standby, suspend, off; ARGBEGIN { case 'v': @@ -506,6 +508,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()) { @@ -523,6 +539,10 @@ 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); + for (nlocks = 0, s = 0; s < nscreens; s++) { XFreePixmap(dpy, locks[s]->drawable); XFreeGC(dpy, locks[s]->gc); @@ -530,5 +550,6 @@ main(int argc, char **argv) { XSync(dpy, 0); XCloseDisplay(dpy); + return 0; }