[dev] [PATCH] [slock] rework setting window color

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Fri, 8 May 2015 18:13:21 +0200

---
Heyho,
while reviewing the latest slock patch, I noticed code duplication where the
background colors are set. This patch fixes that. If you have any comments, let
me know.
--Markus
 slock.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/slock.c b/slock.c
index 68e813f..d6053af 100644
--- a/slock.c
+++ b/slock.c
_AT_@ -119,11 +119,12 @@ readpw(Display *dpy, const char *pws)
 {
 	char buf[32], passwd[256];
 	int num, screen;
-	unsigned int len, llen;
+	unsigned int len, color;
 	KeySym ksym;
 	XEvent ev;
+	static int oldc = INIT;
 
-	len = llen = 0;
+	len = 0;
 	running = True;
 
 	/* As "slock" stands for "Simple X display locker", the DPMS settings
_AT_@ -174,18 +175,14 @@ readpw(Display *dpy, const char *pws)
 				}
 				break;
 			}
-			if (llen == 0 && len != 0) {
+			color = len ? INPUT : (failure || failonclear ? FAILED : INIT);
+			if (oldc != color) {
 				for (screen = 0; screen < nscreens; screen++) {
-					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[INPUT]);
-					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[failure || failonclear ? FAILED : INIT]);
+					XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[color]);
 					XClearWindow(dpy, locks[screen]->win);
 				}
+				oldc = color;
 			}
-			llen = len;
 		} else if (rr && ev.type == rrevbase + RRScreenChangeNotify) {
 			XRRScreenChangeNotifyEvent *rre = (XRRScreenChangeNotifyEvent*)&ev;
 			for (screen = 0; screen < nscreens; screen++) {
-- 
2.3.6
Received on Fri May 08 2015 - 18:13:21 CEST

This archive was generated by hypermail 2.3.0 : Fri May 08 2015 - 18:24:07 CEST