How to map Caps Lock as the compose key using Xmodmap portably and idempotently

xmodmap

I can't seem to find a way to use Caps Lock as the compose key properly. Some methods are not portable since they require that you detect the key number using something like xev on every host. Other methods result in a ~/.Xmodmap which cannot be passed to xmodmap more than once without bad keysym and similar errors. This makes it difficult to test changes to the file. Is there some way to do this in ~/.Xmodmap?

Best Answer

You are having problems with idempotency because you are using keysym instead of keycode. Think of keycode as being an assignment of a key to a function, while keysym is just a link from a function name to an actual function.

When you use keysym as follows:

keysym Caps_Lock = Multi_key

you essentially delete the name Caps_Lock. Therefore, the next time you run xmodmap and you reference Caps_Lock in this same line, it gets confused.

The correct way to do it is to reassign the keycode directly as follows:

keycode 66 = Multi_key

You can get the keycode from the xev command for example.

Related Question