slock-dpms-1.4.diff (1751B) - raw


      1 diff --git a/config.def.h b/config.def.h
      2 index 9855e21..d01bd38 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
      6  
      7  /* treat a cleared input like a wrong password (color) */
      8  static const int failonclear = 1;
      9 +
     10 +/* time in seconds before the monitor shuts down */
     11 +static const int monitortime = 5;
     12 diff --git a/slock.c b/slock.c
     13 index d2f0886..f65a43b 100644
     14 --- a/slock.c
     15 +++ b/slock.c
     16 @@ -15,6 +15,7 @@
     17  #include <unistd.h>
     18  #include <sys/types.h>
     19  #include <X11/extensions/Xrandr.h>
     20 +#include <X11/extensions/dpms.h>
     21  #include <X11/keysym.h>
     22  #include <X11/Xlib.h>
     23  #include <X11/Xutil.h>
     24 @@ -306,6 +307,7 @@ main(int argc, char **argv) {
     25  	const char *hash;
     26  	Display *dpy;
     27  	int s, nlocks, nscreens;
     28 +	CARD16 standby, suspend, off;
     29  
     30  	ARGBEGIN {
     31  	case 'v':
     32 @@ -366,6 +368,20 @@ main(int argc, char **argv) {
     33  	if (nlocks != nscreens)
     34  		return 1;
     35  
     36 +	/* DPMS magic to disable the monitor */
     37 +	if (!DPMSCapable(dpy))
     38 +		die("slock: DPMSCapable failed\n");
     39 +	if (!DPMSEnable(dpy))
     40 +		die("slock: DPMSEnable failed\n");
     41 +	if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
     42 +		die("slock: DPMSGetTimeouts failed\n");
     43 +	if (!standby || !suspend || !off)
     44 +		die("slock: at least one DPMS variable is zero\n");
     45 +	if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
     46 +		die("slock: DPMSSetTimeouts failed\n");
     47 +
     48 +	XSync(dpy, 0);
     49 +
     50  	/* run post-lock command */
     51  	if (argc > 0) {
     52  		switch (fork()) {
     53 @@ -383,5 +399,9 @@ main(int argc, char **argv) {
     54  	/* everything is now blank. Wait for the correct password */
     55  	readpw(dpy, &rr, locks, nscreens, hash);
     56  
     57 +	/* reset DPMS values to inital ones */
     58 +	DPMSSetTimeouts(dpy, standby, suspend, off);
     59 +	XSync(dpy, 0);
     60 +
     61  	return 0;
     62  }