Creating a custom xkb layout

I really REALLY like the neo keyboard layout. I mean, using a non-standard keyboard layout definitely is a huge drag at times 1 2 but apart from that it makes day to day text editing just so much nicer.

Nonetheless, it's not perfect. And because I already have all the downsides of having a non standard keyboard layout, why not modify it further?

The two things I want

  1. no dead keys: i don't need them and i'd rather not have to press twice every time
  2. sane modifiers: e.g. swap ctrl and meta because it makes emacs (and therefore readline) more sane 3.

Luckily there's xmodmap & xkb. I started out with some hacky xmodmap config that i didn't really know how to persist (especially across sleep/resume) but ended up reading up on xkb 4 5 and writing my own layout.

default partial alphanumeric_keys modifier_keys keypad_keys
xkb_symbols "neo" {
    include "de(neo)"

    // swap lalt & lctl
    replace key <LALT> { [ Control_L, Control_L ] };
    replace key <LCTL> { [ Alt_L, Meta_L ] };

    // replace print / menu with lalt
    replace key <PRSC> { [ Alt_L, Meta_L ] };
    replace key <MENU> { [ Alt_L, Meta_L ] };

    // remove dead keys on first level
    key <AE12> { [ grave ] };
    key <AD12> { [ acute ] };
    key <TLDE> { [ asciicircum ] };

With that symlinked from my dotfiles to /usr/share/X11/xkb/symbols/niklas I can activate it with setxkbmap niklas. Persistence is handled via dconf 6.

$ dconf dump /org/gnome/desktop/input-sources/
current=uint32 0
sources=[('xkb', 'niklas')]
xkb-options=@as []