sites

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

slock-dpms-20170923-fa11589.diff (2260B)


      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..7ab0521 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 @@ -289,6 +290,14 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
     25  	return NULL;
     26  }
     27  
     28 +static void
     29 +monitorreset(Display* dpy, CARD16 standby, CARD16 suspend, CARD16 off)
     30 +{
     31 +	DPMSSetTimeouts(dpy, standby, suspend, off);
     32 +	DPMSForceLevel(dpy, DPMSModeOn);
     33 +	XFlush(dpy);
     34 +}
     35 +
     36  static void
     37  usage(void)
     38  {
     39 @@ -306,6 +315,7 @@ main(int argc, char **argv) {
     40  	const char *hash;
     41  	Display *dpy;
     42  	int s, nlocks, nscreens;
     43 +	CARD16 standby, suspend, off;
     44  
     45  	ARGBEGIN {
     46  	case 'v':
     47 @@ -366,12 +376,28 @@ main(int argc, char **argv) {
     48  	if (nlocks != nscreens)
     49  		return 1;
     50  
     51 +	/* DPMS-magic to disable the monitor */
     52 +	if (!DPMSCapable(dpy))
     53 +		die("slock: DPMSCapable failed\n");
     54 +	if (!DPMSEnable(dpy))
     55 +		die("slock: DPMSEnable failed\n");
     56 +	if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
     57 +		die("slock: DPMSGetTimeouts failed\n");
     58 +	if (!standby || !suspend || !off)
     59 +		/* set values if there arent some */
     60 +		standby = suspend = off = 300;
     61 +
     62 +	DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime);
     63 +	XFlush(dpy);
     64 +
     65  	/* run post-lock command */
     66  	if (argc > 0) {
     67  		switch (fork()) {
     68  		case -1:
     69  			die("slock: fork failed: %s\n", strerror(errno));
     70  		case 0:
     71 +			monitorreset(dpy, standby, suspend, off);
     72 +
     73  			if (close(ConnectionNumber(dpy)) < 0)
     74  				die("slock: close: %s\n", strerror(errno));
     75  			execvp(argv[0], argv);
     76 @@ -383,5 +409,8 @@ main(int argc, char **argv) {
     77  	/* everything is now blank. Wait for the correct password */
     78  	readpw(dpy, &rr, locks, nscreens, hash);
     79  
     80 +	/* reset DPMS values to inital ones */
     81 +	monitorreset(dpy, standby, suspend, off);
     82 +
     83  	return 0;
     84  }