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