XKB Keyboard Layout – Remapping Both Caps Lock and Shift+Caps Lock

keyboard-layoutxkb

I am trying to configure xkb such that Caps Lock is mapped to the Compose key and Shift+Caps Lock functions as the traditional Caps Lock. I put the following in a new file called /usr/share/X11/xkb/symbols/gdwatson:

partial modifier keys
xkb_symbols "compose" {
    key <CAPS> {
        type[Group1] = "TWO_LEVEL",
        symbols[Group1] = [ Multi_key, Caps_Lock ]
    };
};

Then I ran setxkbmap -symbols 'pc+us+gdwatson(compose)', which completed successfully. Caps Lock works as Compose, but Shift+Caps Lock works as Compose instead of Caps Lock. xkbcomp :0.0 reveals the following:

key <CAPS> {
    type= "TWO_LEVEL",
    symbols[Group1]= [       Multi_key,       Multi_key ]
};

The second level symbol mapping is duplicating the first for some reason, rather than the separate value I tried to give it. Does anyone have strong enough xkb-fu to tell me what I've done wrong or how to fix it?

Best Answer

This seems to accomplish what you're looking for.

partial modifier_keys
xkb_symbols "compose" {
    key <CAPS> {
        type[Group1] = "TWO_LEVEL",
        symbols[Group1] = [ Multi_key, Caps_Lock ],
        actions[Group1] = [ NoAction(), LockMods(modifiers=Lock) ]
    };
};

The following resources are invaluable when dealing with XKB (I've linked to the WayBack Machine's mirrors of these pages for future-proofing):

Related Question