openbsd-dots/patches/slock/slock-quickcancel-20160619-65b8d52.diff

47 lines
1.5 KiB
Diff

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);