Customizing your keyboard layout with xkbcomp
This is really going to be a poor excuse for a tutorial, it is just aimed at covering my current setup and nothing else, but maybe it is useful to someone.
I type using the Dvorak Simplified Keyboard (though I'm not especially convinced it has any intrinsic benefits, but that's another story). However, as I type French (but don't use a French Dvorak or the Bépo layout -- another complicated story), I need to have mappings to type the diacritics used in French. (French keyboard mappings provide the diacritics at the expense of some characters being relegated to AltGr combinations, and they have 105 keys, one more than Qwerty keyboards, with the additional key at the bottom right being used for '<' and '>'.)
Debian provides the Dvorak Simplified Keyboard, along with an international
option that allows you to have AltGr combinations to invoke dead keys for common
diacritics, you can obtain it using the following invocation. (Note that in all
of this I am thinking of the X server world, not the ttys, which I don't use and
which use a different mechanism, see loadkeys
.)
setxkbmap -layout dvorak -variant intl -model pc105
However, those combinations are not especially convenient (AltGr-6 for the
circumflex, for instance...), so it is tempting to modify them. I used to carry
an entire
dump of the keyboard configuration, that I edited haphazardly and loaded
with xkbcomp ~/.xmodmaprc $DISPLAY
. I now figured out by skimming
through some documentation (mostly this) how to do so more
cleanly.
Let me assume that the configuration will be stored in
config/xkb
. First create a file map
to load your
current configuration. In my case, I issued:
setxkbmap -layout dvorak -variant intl -model pc105 -option compose:caps -print > map
You should be able to load this file by issuing xkbcomp
~/config/xkb/map $DISPLAY
. Next, create a subfolder
symbols
that will contain the various files storing the
customizations. I have altgr that
sets up AltGr (the right alt key) to be used as a modifier, space
that sets up a combination to make non-breaking spaces (both AltGr and Maj as
I don't want to make them accidentally), and a file accents that
stores all of the accents that I need: both dead keys, and shortcuts to make the
most common accented characters directly. On Debian systems, see package
x11proto-core-dev
, file /usr/include/X11/keysymdef.h
,
for the possible symbols.
Now, you can add to the "xkb_symbols" line of the map
file a
reference to your extension files: separated by spaces, first the name of the
file and then between brackets the name of the stanza (they match in my
examples). This gives the final map file.
Last, you need to be able to invoke it. You need to specify where to search for the extension files, so the complete invocation is:
xkbcomp -I$HOME/config/xkb ~/config/xkb/map $DISPLAY
Do not worry about the many warnings. I run this script at the start of my X session to set up the layout (and to set the delay and rate for typematic (the delay after which keys repeat when you keep them pressed) to something that's reasonably fast).