CAPS LOCK IT AWAY
In the interest of getting some kind of blog post in, I wanted to take a break from all the setup talk and talk about my least favorite key on the keyboard: the caps lock key.
It’s right by the left pinky, tantalizing with potential keybinding power. It’s (almost) as large as the enter key over on the right side. However, its only function is to be pushed down when my grandfather fires up his email client. I can’t think of a single time I’ve appreciated a key that does so little being in such a prominent spot.
Almost any other key would be better. Control is used by almost every application I can point to, most importantly my beloved operating system. I use the windows key to control my window manager.
Xmodmap
When I first started feeling frustration with the Caps lock occupying the prime real estate, I went the old fashioned way with Xmodmap(1). It allows you to remap keysyms to others when passed to your X server. I dutifully hunted down all the right ways to go about ridding myself of CAPS lock and making it into another Left Control button.
clear lock
clear control
clear mod1
clear mod2
clear mod3
clear mod4
clear mod5
keycode 37 = Super_L
keycode 66 = Control_L
keycode 108 = Alt_R
add control = Control_L Control_R
add mod1 = Alt_L Meta_L
add mod2 = Num_Lock
add mod3 = Hyper_L
add mod4 = Super_L Super_R
add mod5 = Alt_R
And it’s THAT EASY FOLKS!. Couple issues I had with this approach, though. In order of pain level:
Finding the keysym’s correct ID is hard and I’m lazy
man xmodmap xev
Xmodmap needed to be called when starting up the X11 server
This lead to lots of implementation headaches. Was I using
startx(1)
or a display manager to start X? What init files did they read from? How do I share the config between OS’s?A second consequence here is I cannot remapped keycodes in a console. No X server == no remapped keysyms.
Hotplugged devices didn’t get the mapped values applied to them
I would switch to my work computer with a basic KVM switch in the mornings once I started working from home, only to find that the keymaps I had so lovingly introduced left as soon as someone new showed up to the party.
Once it was setup though, I didn’t find it too terribly onerous. It stayed like that for a while.
XKB
At some point Xorg deprecated xmodmap and began using the XKB for
configuring keyboards under X11. So I switched over and have been using
setxkbmap(1)
manually since then to achieve the same thing.
I won’t go into the dark art of creating your own xkbcomp, but luckily for me,
some beautiful person didn’t like CAPS lock either and already made a preset for
me under (on my system) /usr/share/X11/xkb/rules/base
. All I have to do is use
the option in the rules file with an invocation of setxkbmap.
$ setxkbmap -option ctrl:swapcaps
I mitigated the least painful part at least - no more low-level keysym
remapping. But it still needed to be called when X11 started up and settings
still weren’t applied when devices got plugged in. For the past few years I’ve
just been rerunning setxkbmap
when hotplugging, and dealing with it in the
console.
keyboard(5)
I recently installed OpenBSD on some machines and noticed in the installer that this type of keyboard layout was available effortlessly (thank you yet again OpenBSD). You just select the keyboard layout as part of configuring the system during installation using the wsconsctl mapping. It’s also available on the console.
Given how easy it was, it made me go root around looking for some way to mitigate the rest of my pain points.
Finally found /etc/default/keyboard
on my Debian systems. You can set the XKB
options right there, they’re applied on hotplug and read by the console-setup(1)
subsystem so it’s applicable in a console as well! Great success.
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="ctrl:swapcaps,shift:both_capslock"
Just thought I’d share in case anyone else found it useful.
Jared
100 Days: Day 4