commit 21b2f17707ec9adbf894d788875deb9b12f86563 from: Benjamin Stürz date: Sun Dec 17 16:48:20 2023 UTC slock: turn off display after 3 seconds commit - 784ff9a710309b990c770398d04804cca3488986 commit + 21b2f17707ec9adbf894d788875deb9b12f86563 blob - b1704fa7b09d192d8c43f58d074b11e6112b3be3 blob + 620b41937d24c48796a0c6a4ef14b188cd41a952 --- slock/config.h +++ slock/config.h @@ -11,6 +11,9 @@ static const char *colorname[NUMCOLS] = { /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; +/* time in seconds before monitor shuts down */ +static const int monitortime = 3; + /* allow control key to trigger fail on clear */ static const int controlkeyclear = 0; blob - 6f285abb0082a1e10b79990cecc07fd42b7472cc blob + f8148ac3ee2553004f8efa4165f5c037b1aaad6c --- slock/slock.c +++ slock/slock.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -351,6 +352,7 @@ main(int argc, char **argv) { #endif Display *dpy; int s, nlocks, nscreens; + CARD16 standby, suspend, off; ARGBEGIN { case 'v': @@ -421,6 +423,21 @@ 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()) { @@ -446,5 +463,9 @@ main(int argc, char **argv) { readpw(dpy, &rr, locks, nscreens, hash); #endif + /* reset DPMS values to inital ones */ + DPMSSetTimeouts(dpy, standby, suspend, off); + XSync(dpy, 0); + return 0; }