commit 862fbea54a1e191001302c3b4dbfc420f70b37ce
Author: Matthias Schoth <[email protected]>
Date:   Wed Mar 16 23:51:01 2016 +0100

    [slock] Introducing quickcancel patch

diff --git a/tools.suckless.org/slock/patches/quickcancel.md 
b/tools.suckless.org/slock/patches/quickcancel.md
new file mode 100644
index 0000000..5e5e518
--- /dev/null
+++ b/tools.suckless.org/slock/patches/quickcancel.md
@@ -0,0 +1,28 @@
+quickcancel
+===========
+
+Description
+-----------
+
+Allow slock to be cancelled by simple mouse movement within the
+first 3 seconds after starting.
+
+This is usefull if you forgot to disable `xautolock` during
+an activity that requires no input (e.g. reading text, watching video).
+
+Notes
+-----
+
+The number of seconds while the lock can be cancelled is configured
+in `config.h` via the `timetocancel` option.
+
+Download
+--------
+
+ * [slock-20160316-quickcancel.diff](slock-20160316-quickcancel.diff)
+
+Authors
+-------
+
+ * Matthias Schoth - [email protected]
+
diff --git a/tools.suckless.org/slock/patches/slock-20160316-quickcancel.diff 
b/tools.suckless.org/slock/patches/slock-20160316-quickcancel.diff
new file mode 100644
index 0000000..4317099
--- /dev/null
+++ b/tools.suckless.org/slock/patches/slock-20160316-quickcancel.diff
@@ -0,0 +1,47 @@
+diff --git a/config.def.h b/config.def.h
+index eae2d9a..fbc8f13 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -6,3 +6,6 @@ static const char *colorname[NUMCOLS] = {
+ 
+ /* treat a cleared input like a wrong password */
+ static const int failonclear = 1;
++
++/* time to cancel lock with mouse movement in seconds */
++static const int timetocancel = 3;
+diff --git a/slock.c b/slock.c
+index c9cdee2..a187d7a 100644
+--- a/slock.c
++++ b/slock.c
+@@ -12,6 +12,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>
+@@ -46,6 +47,7 @@ static Bool failure = False;
+ static Bool rr;
+ static int rrevbase;
+ static int rrerrbase;
++static time_t tim;
+ 
+ static void
+ die(const char *errstr, ...)
+@@ -134,6 +136,7 @@ readpw(Display *dpy, const char *pws)
+        * utility. This way the user can easily set a customized DPMS
+        * timeout. */
+       while (running && !XNextEvent(dpy, &ev)) {
++                running = !((time(NULL) - tim < timetocancel) && (ev.type == 
MotionNotify));
+               if (ev.type == KeyPress) {
+                       buf[0] = 0;
+                       num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 
0);
+@@ -261,6 +264,7 @@ lockscreen(Display *dpy, int screen)
+                       if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, 
GrabModeAsync, CurrentTime) == GrabSuccess) {
+                               /* everything fine, we grabbed both inputs */
+                               XSelectInput(dpy, lock->root, 
SubstructureNotifyMask);
++                                tim = time(NULL);
+                               return lock;
+                       }
+                       usleep(1000);


Reply via email to