1

I wonder how I can remap some keys (especially modifier keys) in a way that will hopefully continue to work for the forseeable future, will probably work on different machines and preferrably use files in my home directory so that I can back it up during normal home backup.

I'm on Debian testing with i3 window manager. I've just found a way to accomplish the following:

  1. Map left windows key to Hyper_L
  2. Make Mod3 Hyper_L
  3. Let i3 use Mod3 as its mod-key.

I do this by executing the following in .xsession:

setxkbmap -layout us -option ctrl:swapcaps -option altwin:alt_super_win
xmodmap /home/eike/.config/xmodmaprc
xmodmap /home/eike/.config/xmodmaprc

and configuring i3 to use Mod3 in its config file.

The file ~/.config/xmodmaprc contains this:

keycode 133 = Hyper_L
remove mod4 = Hyper_L
add mod3 = Hyper_L

I run xmodmap twice because its first invocation yields

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  118 (X_SetModifierMapping)
  Value in failed request:  0x17
  Serial number of failed request:  14
  Current serial number in output stream:  14

The second invocation silently works as expected. (This also happens when run in an interactive shell).

My problem with this is the following:

  1. I would not like to use keycodes as they can differ from keyboard to keyboard.
  2. The solution seems extremely hacky and fragile, especially the double invocation to work around the error.
  3. People on the internet (best source ever...) claim that xmodmap is depreciated.

Can somebody help me?

A first step that would make me happier would be to use only xkbmap, as I have hopes that it is so widespread that it may be made compatible with wayland eventually.

Eike
  • 191
  • 1
  • 4
  • Perhaps you're looking for xkb? https://wiki.archlinux.org/index.php/X_keyboard_extension#Simple_key_assignment – preferred_anon Jan 26 '21 at 14:58
  • I think so, yes. It's just that I have no idea, were to put those commands. Must I put them in `/usr/share/X11/xkb/symbols/us`? If so, only root can do that, which I would like to avoid. Can I have an xkblayout in my home directory? – Eike Jan 26 '21 at 15:01
  • The article is very detailed, I recommend reading it from the start. I don't know xkb very well (xmodmap has been sufficient for me in the past), but they explain how to build a per-user configuration using `xkbcomp`: https://wiki.archlinux.org/index.php/X_keyboard_extension#Using_keymap I don't know anything about Wayland, I'm afraid. – preferred_anon Jan 26 '21 at 15:10
  • Thanks, that part of the wiki looks exactly right for me! I'll have a look into that, looks very promising. – Eike Jan 26 '21 at 15:38
  • Could you use `xbindkeys` instead as a workaround? [Shortcut keys that are independent to keyboard layout](https://unix.stackexchange.com/q/91355) – terdon Jan 26 '21 at 16:22
  • I do use xbindkeys for most of my shortcuts but I don't think it can shuffle around modifiers. I need a Super key for emacs that doesn't interfere with i3, so I don't just want to run some program on pressing the respective keys. – Eike Jan 26 '21 at 16:30

0 Answers0