slock-quickcancel-1.4.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       slock-quickcancel-1.4.diff (1931B)
       ---
            1 From e37f8981efe54bc620cb2f2280832cdab3959a32 Mon Sep 17 00:00:00 2001
            2 From: aleks <aleks.stier@icloud.com>
            3 Date: Thu, 10 Oct 2019 17:35:27 +0200
            4 Subject: [PATCH] Apply quickcancel
            5 
            6 Cancel slock by moving the mouse within a certain time-period after
            7 slock started. The time-period can be defined in seconds with the
            8 setting *timetocancel* in the config.h. This is useful if you forgot to
            9 disable `xautolock` during an activity that requires no input (e.g.
           10 reading text, watching video).
           11 ---
           12  config.def.h | 3 +++
           13  slock.c      | 5 +++++
           14  2 files changed, 8 insertions(+)
           15 
           16 diff --git a/config.def.h b/config.def.h
           17 index 9855e21..e0bf95a 100644
           18 --- a/config.def.h
           19 +++ b/config.def.h
           20 @@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
           21  
           22  /* treat a cleared input like a wrong password (color) */
           23  static const int failonclear = 1;
           24 +
           25 +/* time in seconds to cancel lock with mouse movement */
           26 +static const int timetocancel = 4;
           27 diff --git a/slock.c b/slock.c
           28 index d2f0886..f7462ee 100644
           29 --- a/slock.c
           30 +++ b/slock.c
           31 @@ -13,6 +13,7 @@
           32  #include <stdio.h>
           33  #include <string.h>
           34  #include <unistd.h>
           35 +#include <time.h>
           36  #include <sys/types.h>
           37  #include <X11/extensions/Xrandr.h>
           38  #include <X11/keysym.h>
           39 @@ -24,6 +25,8 @@
           40  
           41  char *argv0;
           42  
           43 +static time_t locktime;
           44 +
           45  enum {
           46          INIT,
           47          INPUT,
           48 @@ -141,6 +144,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
           49          oldc = INIT;
           50  
           51          while (running && !XNextEvent(dpy, &ev)) {
           52 +                running = !((time(NULL) - locktime < timetocancel) && (ev.type == MotionNotify));
           53                  if (ev.type == KeyPress) {
           54                          explicit_bzero(&buf, sizeof(buf));
           55                          num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
           56 @@ -268,6 +272,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
           57                                  XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
           58  
           59                          XSelectInput(dpy, lock->root, SubstructureNotifyMask);
           60 +                        locktime = time(NULL);
           61                          return lock;
           62                  }
           63  
           64 -- 
           65 2.23.0
           66