Modifying the behavior of caps lock


It’s been around three years or two since I first used NixOS since the atomic upgrades and reproduceable builds appealed to me, and perhaps around 12 or so since I first used Linux, though I’d still consider myself to be between a beginner and an intermediate user.
Throughout all these years however, caps lock behaves differently than it does on Windows in a subtle way, You can search for “Caps lock delay” for mentions of the issue if you want on your favorite search engine.

Default behavior:
Starting with caps lock being off. Pressing caps lock triggers caps lock on as you expect, and it stays on after releasing caps lock key. Turning caps lock off however, pressing the key does NOT turn of caps lock, releasing caps lock key clears caps lock instead. Basically caps lock gets turned on after pressing the key, but it gets turned off after releasing the key.

It’s a non issue for people that use shift, which is probably why these problems don’t get a lot of traction, but if you capitalize using caps lock, you get this if you type too quickly to release the key.

SO you get an effect like this, WHere the first two letters are capitalized.
You either need to way to release the key, making you write slower, or just write in all caps/lowercase.

Needed behavior:
Caps lock gets turned both on and off after the keypress, not by release.
This is how it works on Windows,
There have been several workarounds that I’ve been using previously, but they’re more of a hack or a band-aid than an actual solution. And you get the effect of a shift effect when you turn caps lock off before releasing the key.

Attempted solutions:

Using xkbmap to modify caps lock behavior. This has worked previously on my previous NixOS installation using i3wm. As well as on Cinnamon on Linux Mint, with the annoying caveat that on Cinnamon, waking up from sleep undoes it.
Regardless, that solution seems to be kinda finnicky, Of all the 3 times I installed i3wm, the workaround worked only once out of 3 times.(Once on an i3wm installation on GalliumOS and the other time on this current installation of NixOS).

There’s another solution that worked to me before on Wayland Gnome using Linux Mint. But it involves modifying the symbols files, which is in the store folder and is read only in NixOS.

I’ve seen the part of the documentation that mentions modifying xkb layouts, but I couldn’t follow it to apply the workaround. And looking at the testing layout section of the documentation, it looks similar to the first x11 workaround anyway.

I’d like a solution (that isn’t just “lol use shift”), preferably a less hacky one, or someone to point a better solution other than attempting to modify the symbols file if possible(which I didn’t figure out how to do anyway).

I’m on system version 23.11 with an i3 and Gnome DE installations.

Thank you for reading.

Maybe interception-tools can help you, it’s basically a small framework to easily remap input events at system level (that works everywhere from the tty, X11, Wayland…).

It is what I use to remap caps to ctrl/esc everywhere for example.

NOTE that you might need to write (or ask someone to write) a small program that does the rewrite you want, and use it in the event pipeline.