20

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>
realh
  • 903
  • 1
    gnome should see your options (and honor the dconf key values under org.gnome.desktop.input-sources) as long as you add them to the xkb rules your system is using, i.e. to the right files, see my post here – don_crissti Jul 06 '16 at 20:00
  • Thanks. Defining options in the evdev files was the missing piece of the puzzle, and I've got it to do what I want now, using dconf-editor. – realh Jul 07 '16 at 14:39
  • On my system (Debian) I also found /usr/share/X11/xkb/rules/evdev.xml. I'm not sure what it's for; the GNOME settings app would crash when opening the Keyboard options if I made a syntax error in it, but I can't actually find the options in the GUI. I added appropriate lines after the line containing <optionList>. I can't post them here because of limitations on comments. – realh Jul 07 '16 at 14:59
  • Allow me to add that xmodmap was deprecated in around 1996 when XKB came up. I.e. years before the invention of wayland. – Robert Siemer Oct 29 '17 at 00:07

1 Answers1

5

don_crissti's answer to the other question provided the missing piece of the puzzle. I've defined options in the evdev files as described and added them to the org.gnome.desktop.input-sources.xkb-options gsetting. It works perfectly.

realh
  • 903
  • could you please explain how exactly you added them to this setting?! – 0xC0000022L Jun 19 '20 at 14:05
  • 1
    The easiest way is with the GNOME tweaks tool. Make sure you also edit /usr/share/X11/xkb/rules/evdev.xml as described here. Then open GNOME tweaks and go to Keyboard & Mouse > Additional Layout Options. The new sections should show up there. – realh Jun 20 '20 at 16:59
  • So basically do what on the CLI can be done with localectl set-x11-keymap ... on modern Linux systems? – 0xC0000022L Jun 20 '20 at 18:46