sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 0e6ef729cb69b8fb3d7c5b1bcd0850a3dfae03df
parent 0db7cfb7f4b03d5e3709cde6fdb0a79007be2966
Author: Alvar Penning <post@0x21.biz>
Date:   Sat, 16 Nov 2019 22:10:41 +0100

[slock][patch][dpms] Fix bug in DPMS patch

In some cases the DPMS settings were not reset, e.g., if the input was
interrupted several times. If the monitor was deactivated by pauses
during input, the reset failed.

This commit also revises the description text and marks the release 1.4
in the file name.

Diffstat:
Mtools.suckless.org/slock/patches/dpms/index.md | 15++++++---------
Atools.suckless.org/slock/patches/dpms/slock-dpms-1.4.diff | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtools.suckless.org/slock/patches/dpms/slock-dpms-20170923-fa11589.diff | 84-------------------------------------------------------------------------------
3 files changed, 68 insertions(+), 93 deletions(-)

diff --git a/tools.suckless.org/slock/patches/dpms/index.md b/tools.suckless.org/slock/patches/dpms/index.md @@ -3,21 +3,18 @@ DPMS Description ----------- -This patch interacts with the Display Power Signaling and automatically shuts -down the monitor after a configurable amount of seconds. The monitor will -automatically be activated by pressing a key or moving the mouse and the -password can be entered then. +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. Notes ----- -The number of seconds until the screen will be disabled is configured in -`config.h` via the `monitortime` option. - -This patch was written against the `1.4`-tag. +The time until the monitor is disabled is configurable as `monitortime` in the +`config.h` file in seconds. Download -------- -* [slock-dpms-20170923-fa11589.diff](slock-dpms-20170923-fa11589.diff) +* [slock-dpms-1.4.diff](slock-dpms-1.4.diff) Authors ------- diff --git a/tools.suckless.org/slock/patches/dpms/slock-dpms-1.4.diff b/tools.suckless.org/slock/patches/dpms/slock-dpms-1.4.diff @@ -0,0 +1,62 @@ +diff --git a/config.def.h b/config.def.h +index 9855e21..d01bd38 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = { + + /* treat a cleared input like a wrong password (color) */ + static const int failonclear = 1; ++ ++/* time in seconds before the monitor shuts down */ ++static const int monitortime = 5; +diff --git a/slock.c b/slock.c +index d2f0886..f65a43b 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> +@@ -306,6 +307,7 @@ main(int argc, char **argv) { + const char *hash; + Display *dpy; + int s, nlocks, nscreens; ++ CARD16 standby, suspend, off; + + ARGBEGIN { + case 'v': +@@ -366,6 +368,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()) { +@@ -383,5 +399,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; + } diff --git a/tools.suckless.org/slock/patches/dpms/slock-dpms-20170923-fa11589.diff b/tools.suckless.org/slock/patches/dpms/slock-dpms-20170923-fa11589.diff @@ -1,84 +0,0 @@ -diff --git a/config.def.h b/config.def.h -index 9855e21..d01bd38 100644 ---- a/config.def.h -+++ b/config.def.h -@@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = { - - /* treat a cleared input like a wrong password (color) */ - static const int failonclear = 1; -+ -+/* time in seconds before the monitor shuts down */ -+static const int monitortime = 5; -diff --git a/slock.c b/slock.c -index d2f0886..7ab0521 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> -@@ -289,6 +290,14 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) - return NULL; - } - -+static void -+monitorreset(Display* dpy, CARD16 standby, CARD16 suspend, CARD16 off) -+{ -+ DPMSSetTimeouts(dpy, standby, suspend, off); -+ DPMSForceLevel(dpy, DPMSModeOn); -+ XFlush(dpy); -+} -+ - static void - usage(void) - { -@@ -306,6 +315,7 @@ main(int argc, char **argv) { - const char *hash; - Display *dpy; - int s, nlocks, nscreens; -+ CARD16 standby, suspend, off; - - ARGBEGIN { - case 'v': -@@ -366,12 +376,28 @@ 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) -+ /* set values if there arent some */ -+ standby = suspend = off = 300; -+ -+ DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime); -+ XFlush(dpy); -+ - /* run post-lock command */ - if (argc > 0) { - switch (fork()) { - case -1: - die("slock: fork failed: %s\n", strerror(errno)); - case 0: -+ monitorreset(dpy, standby, suspend, off); -+ - if (close(ConnectionNumber(dpy)) < 0) - die("slock: close: %s\n", strerror(errno)); - execvp(argv[0], argv); -@@ -383,5 +409,8 @@ 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 */ -+ monitorreset(dpy, standby, suspend, off); -+ - return 0; - }