[dev] [slock] [PATCH] Ctrl-u now resets the input

From: Troy Sankey <sankeytms_AT_gmail.com>
Date: Sun, 05 Jun 2016 17:22:08 -0400

Before this commit, only pressing Escape would reset the input. This commit
makes Ctrl-u do the same. Rationale: it more closely mimics behavior of
login(1)/getpass(3).
---
 slock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/slock.c b/slock.c
index c9cdee2..c3c3ebc 100644
--- a/slock.c
+++ b/slock.c
_AT_@ -125,6 +125,7 @@ readpw(Display *dpy, const char *pws)
        KeySym ksym;
        XEvent ev;
        static int oldc = INIT;
+       Bool control_pressed;
        len = 0;
        running = True;
_AT_@ -137,6 +138,7 @@ readpw(Display *dpy, const char *pws)
                if (ev.type == KeyPress) {
                        buf[0] = 0;
                        num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
+                       control_pressed = !!(ev.xkey.state & ControlMask);
                        if (IsKeypadKey(ksym)) {
                                if (ksym == XK_KP_Enter)
                                        ksym = XK_Return;
_AT_@ -171,7 +173,9 @@ readpw(Display *dpy, const char *pws)
                                        --len;
                                break;
                        default:
-                               if (num && !iscntrl((int)buf[0]) && (len + num < sizeof(passwd))) {
+                               if (control_pressed && ksym == XK_u) {
+                                       len = 0;
+                               } else if (num && !iscntrl((int)buf[0]) && (len + num < sizeof(passwd))) {
                                        memcpy(passwd + len, buf, num);
                                        len += num;
                                }
Received on Sun Jun 05 2016 - 23:22:08 CEST

This archive was generated by hypermail 2.3.0 : Sun Jun 05 2016 - 23:24:11 CEST