Hyper and Super on my keyboard?

Posted on 2019-07-21

Hyper and Super

I want my keyboard to have nearly all the modifier keys. That means I want keys for Alt, Meta, Hyper, and Super.

Why? XMonad!

I switched my window manager to xmonad before I started at the recurse center, but I still hadn’t figured out how to get back my old familiar keyboard bindings. Previously I had Super-n switch to the next Xinerama display, and Hyper-n switch to the next application on the active display. At the time I used xmodmap to turn some of the thumb keys on a kinesis contoured keyboard into hyper and super, but xmodmap isn’t the way things work these days.

If you’re not familiar with keyboards that have clusters of keys for your thumb, jump to the end and click on the links to the keyboard pictures!


The new way to remap your keyboard with X11 on Linux is xkb and it’s completely different from xmodmap.

I spent a bunch of hours reading and trying things, but the most useful link was by maddduck on linux.com. But that article is old, and clearly copied from somewhere else. Even so, it was the best resource for what I needed, especially once I found madduck’s git repo with the finished changes.

The big obstacle was xkbcomp throwing an error no matter what combination of things I tried. I spent some time with xev hoping that would clarify why my file was failing to pass xkbcomp, but finally realized that xev tells me what value a key press produces, not the actual name of that key! Once I realized I was trying to bind F13, F14, F15, and F16; I removed the references to XF86Launch5 and replaced them with the correct key names.

// Mod5 is super
partial modifier_keys
xkb_symbols "plaidkey" {
  replace key <FK15> { [ VoidSymbol, VoidSymbol ] };
  modifier_map Mod5 { <FK15> };

  replace key <FK13> { [ VoidSymbol, VoidSymbol ] };
  modifier_map Mod5 { <FK13> };

  replace key <FK14> { [ VoidSymbol, VoidSymbol ] };
  modifier_map Mod4 { <FK14> };

  replace key <FK16> { [ VoidSymbol, VoidSymbol ] };
  modifier_map Mod4 { <FK16> };

Madduck’s step by step tutorial told me that I had to specify this as a partial modifier remap that would be overlayed onto a full keymap. The chunk of code above ends up in $HOME/.xkb/symbols/shapr and the source belows ends up in $HOME/.xkb/keymap/default.

default xkb_keymap "default" {
  xkb_keycodes  { include "evdev+aliases(qwerty)"       };
  xkb_types     { include "complete"    };
  xkb_compat    { include "complete"    };
  xkb_symbols   { include "pc+us+inet(evdev)+compose(prsc)+shapr(plaidkey)"  };
  xkb_geometry  { include "pc(pc104)"        };

At that point, I was able to run the command xkbcomp -w3 -I$HOME/.xkb $HOME/.xkb/keymap/default $DISPLAY and almost everything was perfect!

Future work

Some of the many documents I read about xkb claim that xkb can handle hotplug events and per-usb device keyboard layouts. If that’s true, that would save me lots of time. I use the dvorak layout natively, but switch my laptop to qwerty for my ergodox that has dvorak in the firmware. It would be nice to skip that manual step of switching the layout. Even so, the solution above required a solid eight hours of reading docs and just trying things, this part might take longer!

The code above does most things right, but the keys still act as if they are keys to be toggled rather than pure modifier keys This means that just pressing those keys gives an error in emacs <VoidSymbol> is undefined. Not sure how to fix that, but would be nice to figure out.

In the original tutorial, madduck has his settings loaded in his .xsession but I’m not sure how to hook that into the display manager I’m using in Ubuntu. I’ve found that gdm3 has a shell script /etc/gdm3/Xsession that has some sort of hooks to load user level xkb files, but it also has a comment # Eeek, this seems like too much magic here so I wonder if there’s a better approach. On the good side, that shell script tells me to put all my xkb into $HOME/.Xkbmap so at least I know where to try this.s

Pretty keyboard pictures

At the recurse center I’m using an ergodox infinity with elvish keycaps. In my storage unit waits my other ergodox infinity with oblotzky oblivion keycaps. My significant other is using the third ergodox with the light version of those same keycaps.