slock-capscolor-20220921-35633d4.diff (2435B)
1 From da1721b1b4bb0aa8f94537ddd2a3eada1df00a30 Mon Sep 17 00:00:00 2001 2 From: Max Schillinger <maxschillinger@web.de> 3 Date: Wed, 21 Sep 2022 19:56:58 +0200 4 Subject: [PATCH] Update capscolor patch to match the latest slock commit 5 (35633d4) 6 7 --- 8 config.def.h | 1 + 9 slock.c | 15 ++++++++++++--- 10 2 files changed, 13 insertions(+), 3 deletions(-) 11 12 diff --git a/config.def.h b/config.def.h 13 index 9855e21..6288856 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -6,6 +6,7 @@ static const char *colorname[NUMCOLS] = { 17 [INIT] = "black", /* after initialization */ 18 [INPUT] = "#005577", /* during input */ 19 [FAILED] = "#CC3333", /* wrong password */ 20 + [CAPS] = "red", /* CapsLock on */ 21 }; 22 23 /* treat a cleared input like a wrong password (color) */ 24 diff --git a/slock.c b/slock.c 25 index 5ae738c..5f4fb7a 100644 26 --- a/slock.c 27 +++ b/slock.c 28 @@ -18,6 +18,7 @@ 29 #include <X11/keysym.h> 30 #include <X11/Xlib.h> 31 #include <X11/Xutil.h> 32 +#include <X11/XKBlib.h> 33 34 #include "arg.h" 35 #include "util.h" 36 @@ -28,6 +29,7 @@ enum { 37 INIT, 38 INPUT, 39 FAILED, 40 + CAPS, 41 NUMCOLS 42 }; 43 44 @@ -130,16 +132,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 45 { 46 XRRScreenChangeNotifyEvent *rre; 47 char buf[32], passwd[256], *inputhash; 48 - int num, screen, running, failure, oldc; 49 - unsigned int len, color; 50 + int caps, num, screen, running, failure, oldc; 51 + unsigned int len, color, indicators; 52 KeySym ksym; 53 XEvent ev; 54 55 len = 0; 56 + caps = 0; 57 running = 1; 58 failure = 0; 59 oldc = INIT; 60 61 + if (!XkbGetIndicatorState(dpy, XkbUseCoreKbd, &indicators)) 62 + caps = indicators & 1; 63 + 64 while (running && !XNextEvent(dpy, &ev)) { 65 if (ev.type == KeyPress) { 66 explicit_bzero(&buf, sizeof(buf)); 67 @@ -179,6 +185,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 68 if (len) 69 passwd[--len] = '\0'; 70 break; 71 + case XK_Caps_Lock: 72 + caps = !caps; 73 + break; 74 default: 75 if (num && !iscntrl((int)buf[0]) && 76 (len + num < sizeof(passwd))) { 77 @@ -187,7 +196,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 78 } 79 break; 80 } 81 - color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT); 82 + color = len ? (caps ? CAPS : INPUT) : (failure || failonclear ? FAILED : INIT); 83 if (running && oldc != color) { 84 for (screen = 0; screen < nscreens; screen++) { 85 XSetWindowBackground(dpy, 86 -- 87 2.37.3 88