-
Notifications
You must be signed in to change notification settings - Fork 0
/
slock-dpms-20170923-fa11589.diff
84 lines (79 loc) · 2.21 KB
/
slock-dpms-20170923-fa11589.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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..7ab0521 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>
@@ -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)
{
@@ -306,6 +315,7 @@ main(int argc, char **argv) {
const char *hash;
Display *dpy;
int s, nlocks, nscreens;
+ CARD16 standby, suspend, off;
ARGBEGIN {
case 'v':
@@ -366,12 +376,28 @@ 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)
+ /* set values if there arent some */
+ standby = suspend = off = 300;
+
+ DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime);
+ XFlush(dpy);
+
/* run post-lock command */
if (argc > 0) {
switch (fork()) {
case -1:
die("slock: fork failed: %s\n", strerror(errno));
case 0:
+ monitorreset(dpy, standby, suspend, off);
+
if (close(ConnectionNumber(dpy)) < 0)
die("slock: close: %s\n", strerror(errno));
execvp(argv[0], argv);
@@ -383,5 +409,8 @@ 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);
+
return 0;
}