Xmodmap and “XKB: Couldn’t compile keymap”

A while ago when I upgraded my distribution, several keys went wonky on me and ceased functioning according to my wishes. It was a minor inconvenience to have things like the Caps Lock key become enabled again. So I pecked around at fixing it here and there, but never really put in much thought or effort until today.

I remap my keys with the /etc/X11/xinit/.Xmodmap (aka ~/.Xmodmap) file. The problem was my .Xmodmap was borking when X started, so no remappings were taking place. (If one part of .Xmodmap fails, they all fail.) In my /var/log/Xorg.0.log I found this:

(EE) Error compiling keymap (server-0)
(EE) XKB: Couldn't compile keymap
(WW) Couldn't load XKB keymap, falling back to pre-XKB keymap

And in the output from X – apparently from the keymap compiler (xkbcomp) – were repeated warnings/errors like this:

Warning:   Duplicate shape name ""
                 Using last definition
Error:        Section defined without a name
                 Definition ignored
Warning:   Multiple doodads named ""
                 Using first definition

Continue reading