diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2020-10-16 00:10:05 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2020-10-16 00:10:05 -0400 |
commit | b5c81157067c256f16242b7488b1112e8fa13175 (patch) | |
tree | 5e1dca710f1a42f043dd38df42ff1512ec2a22de /slock.c | |
parent | 35633d45672d14bd798c478c45d1a17064701aa9 (diff) |
Apply patches
Diffstat (limited to 'slock.c')
-rw-r--r-- | slock.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -13,8 +13,10 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <time.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> @@ -24,6 +26,8 @@ char *argv0; +static time_t locktime; + enum { INIT, INPUT, @@ -141,6 +145,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, oldc = INIT; while (running && !XNextEvent(dpy, &ev)) { + running = !((time(NULL) - locktime < timetocancel) && (ev.type == MotionNotify)); if (ev.type == KeyPress) { explicit_bzero(&buf, sizeof(buf)); num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0); @@ -276,6 +281,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); XSelectInput(dpy, lock->root, SubstructureNotifyMask); + locktime = time(NULL); return lock; } @@ -314,6 +320,7 @@ main(int argc, char **argv) { const char *hash; Display *dpy; int s, nlocks, nscreens; + CARD16 standby, suspend, off; ARGBEGIN { case 'v': @@ -374,6 +381,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 +412,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; } |