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

With a little googling I came across this thread which gave some insight, but was of little help in fixing the problem. This Arch Linux forum thread has several people using various remapping methods reporting the same error. The thread is marked “Solved,” however, the fixes suggested had no effect on my situation. Daedalus’ suggestion of using the “keyboard” driver did manage to provide me with more helpful error messages that pointed out line numbers. This indicated my Caps_Lock remapping was the culprit.

I quit searching on the error messages and began learning more about xmodmap. I didn’t read anything of much use, but I did come across some examples of xmodmap commands I had never used before. I have always used the ‘clear’ and ‘keycode’ commands to disable Caps_Lock and assign different functions to keys, like this:

clear Lock
keycode 66 = Tab

What I found was the use of the ‘remove’ and ‘keysym’ commands to do the same thing:

remove Lock = Caps_Lock
keysym Caps_Lock = Tab

I tried those, and voila! Problem solved.

I wish I could explain why the old method ceased to work, but I can’t. Both methods are still described in the xmodmap man page, and examples of both still exist there as well. The first thread linked above suggests broken data in keyboard-config-1.3 on X Server 1.4.2. I have keyboard-config-1.4 on X 1.4.2, however, so questions remain. Yet despite no explanation, I hope the fix alone will be helpful to others with similar problems.

Finally, here is my new .Xmodmap, which I have enhanced a bit, for those of you curious about it. Explanations for my remappings are in the comments. As for why I prefer to use the xmodmap method for keyboard mapping, there are several reasons. First, it is a single file containing all changes. Those changes universally affect all programs since it is built into the X server. That means no third-party daemon is needed. Also, .Xmodmap is really very easy to configure once you get used to the xev utility. And last, it uses the xmodmap command which I have been familiar with since I adopted Linux – because once upon a time I had to remap the buttons on my mouse in order to get “advanced functions” (read: the scroll wheel) to work. =-)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s