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
@@ -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;
@@ -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;
@@ -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;
}