sites

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

slock-dpms-20231017-4f04554.diff (2394B)


      1 From 4259049ca8d06a34c828c70298f3a8fdb8c5104c Mon Sep 17 00:00:00 2001
      2 From: mortezadadgar <mortezadadgar97@gmail.com>
      3 Date: Sat, 23 Sep 2023 18:45:58 +0330
      4 Subject: [PATCH] Update to respect prevoius state of dpms
      5 
      6 ---
      7  config.def.h |  3 +++
      8  slock.c      | 26 ++++++++++++++++++++++++++
      9  2 files changed, 29 insertions(+)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 9855e21..d01bd38 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
     16  
     17  /* treat a cleared input like a wrong password (color) */
     18  static const int failonclear = 1;
     19 +
     20 +/* time in seconds before the monitor shuts down */
     21 +static const int monitortime = 5;
     22 diff --git a/slock.c b/slock.c
     23 index 5ae738c..b5ac721 100644
     24 --- a/slock.c
     25 +++ b/slock.c
     26 @@ -1,4 +1,5 @@
     27  /* See LICENSE file for license details. */
     28 +#include <X11/Xmd.h>
     29  #define _XOPEN_SOURCE 500
     30  #if HAVE_SHADOW_H
     31  #include <shadow.h>
     32 @@ -15,6 +16,7 @@
     33  #include <unistd.h>
     34  #include <sys/types.h>
     35  #include <X11/extensions/Xrandr.h>
     36 +#include <X11/extensions/dpms.h>
     37  #include <X11/keysym.h>
     38  #include <X11/Xlib.h>
     39  #include <X11/Xutil.h>
     40 @@ -314,6 +316,8 @@ main(int argc, char **argv) {
     41  	const char *hash;
     42  	Display *dpy;
     43  	int s, nlocks, nscreens;
     44 +	CARD16 standby, suspend, off;
     45 +	BOOL dpms_state;
     46  
     47  	ARGBEGIN {
     48  	case 'v':
     49 @@ -374,6 +378,22 @@ main(int argc, char **argv) {
     50  	if (nlocks != nscreens)
     51  		return 1;
     52  
     53 +	/* DPMS magic to disable the monitor */
     54 +	if (!DPMSCapable(dpy))
     55 +		die("slock: DPMSCapable failed\n");
     56 +	if (!DPMSInfo(dpy, &standby, &dpms_state))
     57 +		die("slock: DPMSInfo failed\n");
     58 +	if (!DPMSEnable(dpy) && !dpms_state)
     59 +		die("slock: DPMSEnable failed\n");
     60 +	if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
     61 +		die("slock: DPMSGetTimeouts failed\n");
     62 +	if (!standby || !suspend || !off)
     63 +		die("slock: at least one DPMS variable is zero\n");
     64 +	if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
     65 +		die("slock: DPMSSetTimeouts failed\n");
     66 +
     67 +	XSync(dpy, 0);
     68 +
     69  	/* run post-lock command */
     70  	if (argc > 0) {
     71  		switch (fork()) {
     72 @@ -391,5 +411,11 @@ main(int argc, char **argv) {
     73  	/* everything is now blank. Wait for the correct password */
     74  	readpw(dpy, &rr, locks, nscreens, hash);
     75  
     76 +	/* reset DPMS values to inital ones */
     77 +	DPMSSetTimeouts(dpy, standby, suspend, off);
     78 +	if (!dpms_state)
     79 +		DPMSDisable(dpy);
     80 +	XSync(dpy, 0);
     81 +
     82  	return 0;
     83  }
     84 -- 
     85 2.42.0
     86