[wiki] [sites] [slock][patch][dpms] Fix bug in DPMS patch || Alvar Penning

From: <git_AT_suckless.org>
Date: Sat, 16 Nov 2019 22:13:35 +0100

commit 0e6ef729cb69b8fb3d7c5b1bcd0850a3dfae03df
Author: Alvar Penning <post_AT_0x21.biz>
Date: Sat Nov 16 22:10:41 2019 +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.

diff --git a/tools.suckless.org/slock/patches/dpms/index.md b/tools.suckless.org/slock/patches/dpms/index.md
index 0ba26e4e..5969e0cd 100644
--- a/tools.suckless.org/slock/patches/dpms/index.md
+++ b/tools.suckless.org/slock/patches/dpms/index.md
_AT_@ -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-20170923-fa11589.diff b/tools.suckless.org/slock/patches/dpms/slock-dpms-1.4.diff
similarity index 58%
rename from tools.suckless.org/slock/patches/dpms/slock-dpms-20170923-fa11589.diff
rename to tools.suckless.org/slock/patches/dpms/slock-dpms-1.4.diff
index e0e55196..027bbf77 100644
--- a/tools.suckless.org/slock/patches/dpms/slock-dpms-20170923-fa11589.diff
+++ b/tools.suckless.org/slock/patches/dpms/slock-dpms-1.4.diff
_AT_@ -10,7 +10,7 @@ index 9855e21..d01bd38 100644
 +/* 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
+index d2f0886..f65a43b 100644
 --- a/slock.c
 +++ b/slock.c
 _AT_@ -15,6 +15,7 @@
_AT_@ -21,22 +21,7 @@ index d2f0886..7ab0521 100644
  #include <X11/keysym.h>
  #include <X11/Xlib.h>
  #include <X11/Xutil.h>
-_AT_@ -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)
- {
-_AT_@ -306,6 +315,7 @@ main(int argc, char **argv) {
+_AT_@ -306,6 +307,7 @@ main(int argc, char **argv) {
          const char *hash;
          Display *dpy;
          int s, nlocks, nscreens;
_AT_@ -44,11 +29,11 @@ index d2f0886..7ab0521 100644
  
          ARGBEGIN {
          case 'v':
-_AT_@ -366,12 +376,28 @@ main(int argc, char **argv) {
+_AT_@ -366,6 +368,20 @@ main(int argc, char **argv) {
          if (nlocks != nscreens)
                  return 1;
  
-+ /* DPMS-magic to disable the monitor */
++ /* DPMS magic to disable the monitor */
 + if (!DPMSCapable(dpy))
 + die("slock: DPMSCapable failed
");
 + if (!DPMSEnable(dpy))
_AT_@ -56,29 +41,22 @@ index d2f0886..7ab0521 100644
 + if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
 + die("slock: DPMSGetTimeouts failed
");
 + if (!standby || !suspend || !off)
-+ /* set values if there arent some */
-+ standby = suspend = off = 300;
++ die("slock: at least one DPMS variable is zero
");
++ if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
++ die("slock: DPMSSetTimeouts failed
");
 +
-+ DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime);
-+ XFlush(dpy);
++ XSync(dpy, 0);
 +
          /* run post-lock command */
          if (argc > 0) {
                  switch (fork()) {
- case -1:
- die("slock: fork failed: %s
", strerror(errno));
- case 0:
-+ monitorreset(dpy, standby, suspend, off);
-+
- if (close(ConnectionNumber(dpy)) < 0)
- die("slock: close: %s
", strerror(errno));
- execvp(argv[0], argv);
-_AT_@ -383,5 +409,8 @@ main(int argc, char **argv) {
+_AT_@ -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 */
-+ monitorreset(dpy, standby, suspend, off);
++ DPMSSetTimeouts(dpy, standby, suspend, off);
++ XSync(dpy, 0);
 +
          return 0;
  }
Received on Sat Nov 16 2019 - 22:13:35 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 16 2019 - 22:24:31 CET