Hello,

This patch adds the failonclear boolean option so that, when false,
the failure color will not appear until a failed login attempt has
been made.
It also maintains the existing behaviour (failure on clear) by default.

Thanks,
hexid
From b5fa0f2cabf03ae3d09a29b8fb5327109ec2e0e0 Mon Sep 17 00:00:00 2001
From: hexid <nick.curr...@gmail.com>
Date: Fri, 17 Apr 2015 11:09:02 -0600
Subject: [PATCH] Add config option to only show error color if after a
 failed login attempt

---
 config.def.h |  3 ++-
 slock.c      | 20 +++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/config.def.h b/config.def.h
index 4bccb5d..3ae2e6e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,5 +1,6 @@
 static const char *colorname[NUMCOLS] = {
 	"black",     /* after initialization */
 	"#005577",   /* during input */
 	"#CC3333",   /* failed/cleared the input */
 };
+static const Bool failonclear = True;
diff --git a/slock.c b/slock.c
index 6502c86..8a12cde 100644
--- a/slock.c
+++ b/slock.c
@@ -26,7 +26,7 @@
 enum {
 	INIT,
 	INPUT,
-	EMPTY,
+	FAILED,
 	NUMCOLS
 };
 
@@ -42,6 +42,7 @@ typedef struct {
 static Lock **locks;
 static int nscreens;
 static Bool running = True;
+static Bool failure = False;
 static Bool rr;
 static int rrevbase;
 static int rrerrbase;
@@ -153,8 +154,10 @@ readpw(Display *dpy, const char *pws)
 #else
 				running = !!strcmp(crypt(passwd, pws), pws);
 #endif
-				if (running)
+				if (running) {
 					XBell(dpy, 100);
+					failure = True;
+				}
 				len = 0;
 				break;
 			case XK_Escape:
@@ -177,9 +180,16 @@ readpw(Display *dpy, const char *pws)
 					XClearWindow(dpy, locks[screen]->win);
 				}
 			} else if (llen != 0 && len == 0) {
-				for (screen = 0; screen < nscreens; screen++) {
-					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[EMPTY]);
-					XClearWindow(dpy, locks[screen]->win);
+				if (failure || failonclear) {
+					for (screen = 0; screen < nscreens; screen++) {
+						XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[FAILED]);
+						XClearWindow(dpy, locks[screen]->win);
+					}
+				} else {
+					for (screen = 0; screen < nscreens; screen++) {
+						XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[INIT]);
+						XClearWindow(dpy, locks[screen]->win);
+					}
 				}
 			}
 			llen = len;
-- 
2.3.5

Reply via email to