slock/patches/slock-capscolor-20170106-2d2a21a.diff
2021-06-02 08:25:14 +02:00

88 lines
2.4 KiB
Diff

From 95463f58beb669d9221881deac3b6df7d9c4f162 Mon Sep 17 00:00:00 2001
From: Klemens Nanni <kl3@posteo.org>
Date: Fri, 2 Sep 2016 14:53:30 +0200
Subject: [PATCH] Indicate the state of CapsLock through a different color
---
config.def.h | 1 +
slock.c | 15 ++++++++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h
index 9855e21..6288856 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) */
diff --git a/slock.c b/slock.c
index d55eb3d..d7804f1 100644
--- a/slock.c
+++ b/slock.c
@@ -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,
--
2.11.0