diff options
author | Malfurious <m@lfurio.us> | 2021-10-03 20:29:22 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-06-01 21:23:59 -0400 |
commit | 505fe537796a38ea4a7023df0d938c0a2a43cc64 (patch) | |
tree | 57e96d230682ed4602cc8c74a4b18cedbe6d8598 | |
parent | 7b78bbad780cc7a90de1242763835af0c1f9efe1 (diff) | |
download | slock-505fe537796a38ea4a7023df0d938c0a2a43cc64.tar.gz slock-505fe537796a38ea4a7023df0d938c0a2a43cc64.zip |
patch: capscolor
Introduces an additional color to indicate the state of Caps Lock.
Written against HEAD at a31b919, but should apply to 1.2.
-rw-r--r-- | config.def.h | 1 | ||||
-rw-r--r-- | slock.c | 15 |
2 files changed, 13 insertions, 3 deletions
diff --git a/config.def.h b/config.def.h index 27cc2d0..83e4887 100644 --- a/config.def.h +++ b/config.def.h @@ -6,6 +6,7 @@ static const char *colorname[NUMCOLS] = { [INIT] = "black", /* after initialization */ [INPUT] = "#005577", /* during input */ [FAILED] = "#CC3333", /* wrong password */ + [CAPS] = "red", /* CapsLock on */ }; /* treat a cleared input like a wrong password (color) */ @@ -18,6 +18,7 @@ #include <X11/keysym.h> #include <X11/Xlib.h> #include <X11/Xutil.h> +#include <X11/XKBlib.h> #include "arg.h" #include "util.h" @@ -28,6 +29,7 @@ enum { INIT, INPUT, FAILED, + CAPS, NUMCOLS }; @@ -130,16 +132,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, { XRRScreenChangeNotifyEvent *rre; char buf[32], passwd[256], *inputhash; - int num, screen, running, failure, oldc; - unsigned int len, color; + int caps, num, screen, running, failure, oldc; + unsigned int len, color, indicators; KeySym ksym; XEvent ev; len = 0; + caps = 0; running = 1; failure = 0; oldc = INIT; + if (!XkbGetIndicatorState(dpy, XkbUseCoreKbd, &indicators)) + caps = indicators & 1; + while (running && !XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { explicit_bzero(&buf, sizeof(buf)); @@ -179,6 +185,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, if (len) passwd[--len] = '\0'; break; + case XK_Caps_Lock: + caps = !caps; + break; default: if (num && !iscntrl((int)buf[0]) && (len + num < sizeof(passwd))) { @@ -187,7 +196,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, } break; } - color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT); + color = len ? (caps ? CAPS : INPUT) : (failure || failonclear ? FAILED : INIT); if (running && oldc != color) { for (screen = 0; screen < nscreens; screen++) { XSetWindowBackground(dpy, |