~ob/slock

2a7851a9f4e541d3a71ff34fe0015abfed5c1105 — Oscar Benedito 1 year, 3 months ago 35633d4
Applied DPMS patch

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.
3 files changed, 85 insertions(+), 0 deletions(-)

M config.def.h
A patches/slock-dpms-1.4.diff
M slock.c
M config.def.h => config.def.h +3 -0
@@ 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;

A patches/slock-dpms-1.4.diff => patches/slock-dpms-1.4.diff +62 -0
@@ 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;
 }

M slock.c => slock.c +20 -0
@@ 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>


@@ 314,6 315,7 @@ main(int argc, char **argv) {
	const char *hash;
	Display *dpy;
	int s, nlocks, nscreens;
	CARD16 standby, suspend, off;

	ARGBEGIN {
	case 'v':


@@ 374,6 376,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()) {


@@ 391,5 407,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;
}