]> git.armaanb.net Git - slock.git/commitdiff
Apply dpms patch master
authorArmaan Bhojwani <me@armaanb.net>
Tue, 25 May 2021 00:53:23 +0000 (20:53 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 25 May 2021 00:53:23 +0000 (20:53 -0400)
config.def.h
slock.c

index 21b6659cd6b002d9480ec7a994069ed0d6a655c5..69859d4ce70e4ebb5e638f9b9ac076642fe83077 100644 (file)
@@ -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 4a10a9430b84db6978e58fe7af349fbeb15cd5e0..2b06ca2a9c3b79c6ef7b9fe6fa2686edab91be7f 100644 (file)
--- a/slock.c
+++ b/slock.c
@@ -16,6 +16,7 @@
 #include <time.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>
@@ -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;
 }