diff --git a/config.def.h b/config.def.h index 9855e21..354980b 100644 --- a/config.def.h +++ b/config.def.h @@ -10,3 +10,12 @@ static const char *colorname[NUMCOLS] = { /* treat a cleared input like a wrong password (color) */ static const int failonclear = 1; + +/* length of time (seconds) until [command] is executed */ +static const int timeoffset = 60; + +/* should [command] be run only once? */ +static const int runonce = 0; + +/* command to be run after [timeoffset] seconds has passed */ +static const char *command = "doas poweroff"; diff --git a/slock.c b/slock.c index 5ae738c..7644bd9 100644 --- a/slock.c +++ b/slock.c @@ -19,11 +19,16 @@ #include #include +#include + #include "arg.h" #include "util.h" char *argv0; +time_t lasttouched; +int runflag = 0; + enum { INIT, INPUT, @@ -140,7 +145,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, failure = 0; oldc = INIT; - while (running && !XNextEvent(dpy, &ev)) { + while (running) { + while (XPending(dpy)) { + XNextEvent(dpy, &ev); if (ev.type == KeyPress) { explicit_bzero(&buf, sizeof(buf)); num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0); @@ -217,6 +224,17 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, XRaiseWindow(dpy, locks[screen]->win); } } + + time_t currenttime; + time(¤ttime); + + if (currenttime >= lasttouched + timeoffset){ + if (!runonce || !runflag){ + runflag = 1; + system(command); + } + } + } } static struct lock * @@ -229,6 +247,8 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) XSetWindowAttributes wa; Cursor invisible; + time(&lasttouched); + if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(struct lock)))) return NULL;