(This answer is about xmodmap only. I'm sure it's possible to do this with XKB, I just don't know how.)
Modifiers and keysyms are assigned independently. But you get strange effects if you don't set them consistently. I think all you're missing is the add
command to assign a modifier to Meta_L
, though you may also need to clear and reassign the modifier keys. You may replace Mod1
and Mod2
by Mod3
, Mod4
and Mod5
: they are interchangeable, just make sure you don't use one for two different purposes.
clear Mod1
clear Mod2
remove Lock = Caps_Lock
keysym Caps_Lock = Alt_L
keysym Alt_L = Meta_L
add Mod1 = Alt_L Alt_R
add Mod2 = Meta_L Meta_R
The xmodmap(1) man page has an example for exactly this
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
but if you want to finish doing it the way you started, I think you need to add at least the remove
and add
lines
remove Lock = Caps_Lock
remove Control = Control_L
keycode 37 = Caps_Lock
keycode 66 = Control_L
add Lock = Caps_Lock
add Control = Control_L
I'm guessing that's the case based on this paragraph
add MODIFIERNAME = KEYSYMNAME ...
This adds all keys containing the given keysyms to the indi‐
cated modifier map. The keysym names are evaluated after all
input expressions are read to make it easy to write expressions
to swap keys (see the EXAMPLES section).
which makes it sound like modifier changes (shift, control, etc.) don't get applied until you run that too.
(And logically the same with remove
)
The keycode
version has the advantage of being idempotent, meaning that the effect won't change if xmodmap is run multiple times.
Best Answer
You are having problems with idempotency because you are using
keysym
instead ofkeycode
. Think ofkeycode
as being an assignment of a key to a function, whilekeysym
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 runxmodmap
and you referenceCaps_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.