From 716d7ac8524d47f244928ae45ca79194cfa2e7ff Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Mon, 24 May 2021 20:53:23 -0400 Subject: [PATCH] Apply dpms patch --- config.def.h | 3 +++ slock.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/config.def.h b/config.def.h index 21b6659..69859d4 100644 --- a/config.def.h +++ b/config.def.h @@ -13,3 +13,6 @@ static const int failonclear = 1; /* time in seconds to cancel lock with mouse movement */ static const int timetocancel = 4; + +/* time in seconds before the monitor shuts down */ +static const int monitortime = timetocancel; diff --git a/slock.c b/slock.c index 4a10a94..2b06ca2 100644 --- a/slock.c +++ b/slock.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -335,6 +336,7 @@ main(int argc, char **argv) { const char *hash; Display *dpy; int s, nlocks, nscreens; + CARD16 standby, suspend, off; ARGBEGIN { case 'v': @@ -395,6 +397,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()) { @@ -412,5 +428,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; } -- 2.39.2