From: Armaan Bhojwani Date: Tue, 25 May 2021 00:50:06 +0000 (-0400) Subject: Apply quickcancel patch X-Git-Url: https://git.armaanb.net/?p=slock.git;a=commitdiff_plain;h=32597530dc387f3cef966b38ebfca97e45128a76 Apply quickcancel patch --- diff --git a/config.def.h b/config.def.h index 9855e21..e0bf95a 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 to cancel lock with mouse movement */ +static const int timetocancel = 4; diff --git a/slock.c b/slock.c index 04665ff..4a10a94 100644 --- a/slock.c +++ b/slock.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,8 @@ char *argv0; +static time_t locktime; + enum { INIT, INPUT, @@ -141,6 +144,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); @@ -292,6 +296,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); XSelectInput(dpy, lock->root, SubstructureNotifyMask); + locktime = time(NULL); return lock; }