[hackers] [slock][PATCH] Reset color to INIT on Escape key press

From: Thomas <thoms3rd_AT_gmail.com>
Date: Mon, 4 Apr 2016 02:46:18 -0300

This is so people who have the INIT color set to black but the FAILURE
color set to something else can still have their monitor black out after
failing to unlock, without having to unlock and lock again.

Also makes sense because pushing Esc isn't really a failure, but a
purposefully aborted unlock attempt, so the background shouldn't be set
to FAILURE.

(Note: let me know if you prefer to pull from Github, I'm new to the
list.)
---
 slock.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/slock.c b/slock.c
index c9cdee2..48f917f 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 reset = False;
 
 	len = 0;
 	running = True;
_AT_@ -165,6 +166,7 @@ readpw(Display *dpy, const char *pws)
 				break;
 			case XK_Escape:
 				len = 0;
+				reset = True;
 				break;
 			case XK_BackSpace:
 				if (len)
_AT_@ -177,7 +179,12 @@ readpw(Display *dpy, const char *pws)
 				}
 				break;
 			}
-			color = len ? INPUT : (failure || failonclear ? FAILED : INIT);
+			if (reset) {
+				color = INIT;
+				reset = False;
+			} else {
+				color = len ? INPUT : (failure || failonclear ? FAILED : INIT);
+			}
 			if (running && oldc != color) {
 				for (screen = 0; screen < nscreens; screen++) {
 					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[color]);
-- 
2.8.0
Received on Mon Apr 04 2016 - 07:46:18 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 04 2016 - 07:48:16 CEST