slock-quickcancel-20160619-65b8d52.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
slock-quickcancel-20160619-65b8d52.diff (1553B)
---
1 diff --git a/config.def.h b/config.def.h
2 index eae2d9a..fbc8f13 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -6,3 +6,6 @@ static const char *colorname[NUMCOLS] = {
6
7 /* treat a cleared input like a wrong password */
8 static const int failonclear = 1;
9 +
10 +/* time to cancel lock with mouse movement in seconds */
11 +static const int timetocancel = 3;
12 diff --git a/slock.c b/slock.c
13 index c9cdee2..a187d7a 100644
14 --- a/slock.c
15 +++ b/slock.c
16 @@ -12,6 +12,7 @@
17 #include <stdio.h>
18 #include <string.h>
19 #include <unistd.h>
20 +#include <time.h>
21 #include <sys/types.h>
22 #include <X11/extensions/Xrandr.h>
23 #include <X11/keysym.h>
24 @@ -46,6 +47,7 @@ static Bool failure = False;
25 static Bool rr;
26 static int rrevbase;
27 static int rrerrbase;
28 +static time_t tim;
29
30 static void
31 die(const char *errstr, ...)
32 @@ -134,6 +136,7 @@ readpw(Display *dpy, const char *pws)
33 * utility. This way the user can easily set a customized DPMS
34 * timeout. */
35 while (running && !XNextEvent(dpy, &ev)) {
36 + running = !((time(NULL) - tim < timetocancel) && (ev.type == MotionNotify));
37 if (ev.type == KeyPress) {
38 buf[0] = 0;
39 num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
40 @@ -261,6 +264,7 @@ lockscreen(Display *dpy, int screen)
41 if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) {
42 /* everything fine, we grabbed both inputs */
43 XSelectInput(dpy, lock->root, SubstructureNotifyMask);
44 + tim = time(NULL);
45 return lock;
46 }
47 usleep(1000);