From: Matthias Schoth Date: Sat, 11 Jul 2026 11:15:49 +0200 Subject: [PATCH] Apply quickcancel Cancel slock by moving the mouse within a certain time-period after slock started. The time-period can be defined in seconds with the setting *timetocancel* in the config.h. This is useful if you forgot to disable `xautolock` during an activity that requires no input (e.g. reading text, watching video). Changes from the 1.4 version: use CLOCK_MONOTONIC instead of time(NULL) to prevent bypassing the lock by setting the system clock back. --- config.def.h | 3 +++ slock.c | 9 +++++++++ 2 files changed, 12 insertions(+) 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 f16781f..212b482 100644 --- a/slock.c +++ b/slock.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,8 @@ char *argv0; +static struct timespec locktime; + enum { INIT, INPUT, @@ -142,6 +145,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, oldc = INIT; while (running && !XNextEvent(dpy, &ev)) { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + running = !((now.tv_sec - locktime.tv_sec < timetocancel) && (ev.type == MotionNotify)); if (ev.type == KeyPress) { explicit_bzero(&buf, sizeof(buf)); num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0); @@ -280,6 +286,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask); XSelectInput(dpy, lock->root, SubstructureNotifyMask); + clock_gettime(CLOCK_MONOTONIC, &locktime); return lock; } -- 2.23.0