summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-09-28 02:16:07 +0200
committerLouis Burda <quent.burda@gmail.com>2023-09-28 02:19:52 +0200
commitfad6aca78f2b54089c44a33da5124f2fd994bf33 (patch)
tree34f3b61b7cc347c2395d88fe34b71bd395debdab
parent5fa767f5f20a025793d4968f9421e946c1612c4b (diff)
downloadslock-fad6aca78f2b54089c44a33da5124f2fd994bf33.tar.gz
slock-fad6aca78f2b54089c44a33da5124f2fd994bf33.zip
Enable powersaving after x seconds
-rw-r--r--config.def.h3
-rw-r--r--slock.c20
2 files changed, 23 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index a329228..12fbb4b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -11,6 +11,9 @@ static const char *colorname[NUMCOLS] = {
/* allow control key to trigger fail on clear */
static const int controlkeyclear = 0;
+/* time in seconds before the monitor shuts down */
+static const int monitortime = 30;
+
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
diff --git a/slock.c b/slock.c
index 8974197..42b4df3 100644
--- a/slock.c
+++ b/slock.c
@@ -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>
@@ -333,6 +334,7 @@ main(int argc, char **argv) {
const char *hash;
Display *dpy;
int s, nlocks, nscreens;
+ CARD16 standby, suspend, off;
ARGBEGIN {
case 'v':
@@ -447,6 +449,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()) {
@@ -464,5 +480,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;
}