Following up on my question about customising key mappings in Wayland I've found out that xmodmap is apparently deprecated, but xkb "should work" in Wayland. Unfortunately, xkb is much more complicated and correspondingly more poorly documented. I've managed to work out the stanzas I need based on information from a question about swapping Cmd and Ctrl, another caps lock question, reading some of the links in the answers and from my system files, but I don't know how to apply them in a way that can be automated and not conflict with GNOME.
These are the stanzas I've worked out, and tested successfully with xkbcomp.
partial alphanumeric_keys
xkb_symbols "pound" {
// Put sterling on RAlt-3 and numbersign on Shift-3.
key <AE03> { [ 3, numbersign, sterling, threesuperior ] };
};
// Make right cmd key act as ctrl
partial modifier_keys
xkb_symbols "rcmdctrl" {
key <RWIN> { [ Control_R ] };
modifier_map Control { <LCTL>, <RWIN> };
modifier_map Mod4 { <LWIN> };
};
partial modifier_keys
xkb_symbols "shiftcaps" {
key <CAPS> {
type[Group1] = "TWO_LEVEL",
symbols[Group1] = [ VoidSymbol, Caps_Lock ],
actions[Group1] = [ NoAction(), LockMods(modifiers=Lock) ]
};
};
I put the first two in /usr/share/X11/xkb/symbols/macbook and the third in shiftcaps in the same directory, and with xkbcomp etc they work when loaded on top of the standard gb(mac) layout.
I'm editing this to make an update and clarify my answer. My pound customisation recently stopped working so I checked what had changed in gb(mac) and realised I had to add , threesuperior to the key <AE03> line.
I think evdev.xml is used by gnome-tweak-tool to make these options available in the GUI. Here is what I added:
<group allowMultipleSelection="true">
<configItem>
<name>macbook</name>
<description>Macbook customisations</description>
</configItem>
<option>
<configItem>
<name>macbook:pound</name>
<description>Hash on Shift-3, Sterling on AltGr-3</description>
</configItem>
</option>
<option>
<configItem>
<name>macbook:rcmdctrl</name>
<description>Right Cmd key acts as Ctrl</description>
</configItem>
</option>
</group>
<group allowMultipleSelection="false">
<configItem>
<name>shiftcaps</name>
<description>Caps Lock with Shift</description>
</configItem>
<option>
<configItem>
<name>shiftcaps:shiftcaps</name>
<description>Caps Lock requires Shift to toggle</description>
</configItem>
</option>
</group>