pancake

Remapping Caps to AltGr

This will be very quick. Jump to the bottom to see the solution.

English isn't my native language, but I've been using the English (US) layout at all times for some time now. Mostly because it is convenient to develop software in, and also because I got used to it and muscle memory prevented me from simply switching layouts on the same physical keyboard.

Now, some (I haven't checked how many) keyboard layouts for non-English speaking users provide US-like layout with local accented or otherwise non-ASCII characters on a third layer: you have to hold AltGr to write them.

I don't know if you have noticed, but it's really hard to hold AltGr with your right thumb and at the same time press the letter 7 on the first row.


I've tried searching online, but most of the blog posts and StackOverflow posts are either from 2010s and use features that are deprecated, removed or otherwise discouraged (and they may not work on Wayland at all). xkbcomp(1) doesn't mention X11 nor Wayland, but setting stuff up requires compiling and updating files on a filesystem, which I'd like to avoid.

Project xremap looked promising, and I even got it to work and intercept Caps presses, but setting everything up required messing with files in /etc/udev/rules.d/ and I wasn't ready for the commitment of remembering and maintaining a file inside the /etc/ directory, and updating my workstation management scripts to handle it properly.

After some fiddling around, I realized that GNOME has dconf map /org/gnome/desktop/input-sources/ with xkb-options key. I've played around with values I thought should work, but nothing I've tried did what I needed. I thought I could use it to literally map Caps Lock to AltGr, so my attempts were mostly something around caps and ralt. Nothing.

I've searched one more time and found a post from 2019 with screenshots of gnome-tweaks running an "Additional Layout Options" window. Bingo. I've found my option under "Key to choose the 3rd level", selected it to get the raw value, and updated my scripts.


tl;dr: To make Caps Lock act like AltGr and switch to the 3rd keyboard layer, run

dconf write /org/gnome/desktop/input-sources/xkb-options "['lv3:caps_switch']"

#altgr #gnome #keyboard