---
 svkbd.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/svkbd.c b/svkbd.c
index 92ddf23..04b5cc8 100644
--- a/svkbd.c
+++ b/svkbd.c
@@ -13,6 +13,7 @@
 #include <X11/Xutil.h>
 #include <X11/Xproto.h>
 #include <X11/extensions/XTest.h>
+#include <X11/XKBlib.h>
 
 /* macros */
 #define MAX(a, b)       ((a) > (b) ? (a) : (b))
@@ -244,8 +245,16 @@ drawkey(Key *k) {
        XRectangle r = { k->x, k->y, k->w, k->h};
        const char *l;
        ulong *col;
+       Bool pressed = k->pressed;
 
-       if(k->pressed)
+       // For the caps lock key get the state to still show it as pressed
+       if (k->keysym == XK_Caps_Lock && !pressed)
+       {
+               unsigned int atom = XInternAtom(dpy, "Caps Lock", False);
+               XkbGetNamedIndicator(dpy, atom, NULL, &pressed, NULL, NULL);
+       }
+
+       if(pressed)
                col = dc.press;
        else if(k->highlighted)
                col = dc.high;
@@ -380,6 +389,18 @@ press(Key *k, KeySym mod) {
                        }
                }
        }
+       else if (k->keysym == XK_Caps_Lock)
+       {
+               // Special case for caps lock
+               // Unlike other modifier keys it's not meant to be held down
+               XTestFakeKeyEvent(dpy,
+                       XKeysymToKeycode(dpy, k->keysym),
+                       True, 0);
+               k->pressed = False;
+               XTestFakeKeyEvent(dpy,
+                       XKeysymToKeycode(dpy, k->keysym),
+                       False, 0);
+       }
        drawkey(k);
 }
 
-- 
1.9.1


Reply via email to