]> git.armaanb.net Git - slock.git/commitdiff
Apply quickcancel patch
authorArmaan Bhojwani <me@armaanb.net>
Tue, 25 May 2021 00:50:06 +0000 (20:50 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 25 May 2021 00:50:06 +0000 (20:50 -0400)
config.def.h
slock.c

index 9855e2117e719998b65367c66fd30f625b3fa7d2..e0bf95a290e7669fdaf7f1fed2ca0e8a02953e00 100644 (file)
@@ -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 04665ffc8fd196828c07b5657c7cf6908599e94d..4a10a9430b84db6978e58fe7af349fbeb15cd5e0 100644 (file)
--- a/slock.c
+++ b/slock.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
 #include <sys/types.h>
 #include <X11/extensions/Xrandr.h>
 #include <X11/keysym.h>
@@ -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;
                }