#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>
char *argv0;
+static time_t locktime;
+
enum {
INIT,
INPUT,
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);
XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
XSelectInput(dpy, lock->root, SubstructureNotifyMask);
+ locktime = time(NULL);
return lock;
}
const char *hash;
Display *dpy;
int s, nlocks, nscreens;
+ CARD16 standby, suspend, off;
ARGBEGIN {
case 'v':
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()) {
/* 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;
}