commit 862fbea54a1e191001302c3b4dbfc420f70b37ce
parent e3d93ca3ca178f19feb14d3844a904dc8880b374
Author: Matthias Schoth <mschoth@gmail.com>
Date: Wed, 16 Mar 2016 23:51:01 +0100
[slock] Introducing quickcancel patch
Diffstat:
2 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/tools.suckless.org/slock/patches/quickcancel.md 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 - mschoth@gmail.com
+
diff --git a/tools.suckless.org/slock/patches/slock-20160316-quickcancel.diff 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);