9

I have used xkb to remap the right windows key (RWIN) to Hyper_R because I want to use it with AutoKey for some special shortcuts. I did it by editing

/usr/share/X11/xkb/symbols/pc

modifying the RWIN line:

  key <RWIN> {  [ Hyper_R   ]   };

(Here's the answer that guided me)

From what I can tell, this works and the right Windows key now fires Hyper_R. However, It seems that in Ubuntu (Xubuntu to be exact), Hyper and Super somehow are doing the same thing. So Super + e launches the editor, and so does Hyper + e.

I'm not sure why this is or where I can change this behavior. I want Hyper and Super to be different modifiers.

  • There was a thing on it here, though I don't think the dialogue now exists in 13.10... – Wilf Feb 20 '14 at 12:32
  • But this has to be configurable somewhere, right? – Alexander Rechsteiner Feb 20 '14 at 12:35
  • You may be able to find them in dconf-editor – Wilf Feb 20 '14 at 12:38
  • 1
    Thanks, but no luck there. Damn, this whole keyboard remapping thing on Linux gives me diabetes. – Alexander Rechsteiner Feb 20 '14 at 12:46
  • +1 :concord (on the diabetes part). I was not able to find a nice, comprehensive, detailed guide on how the keyboard is managed in Ubuntu. There are a series of interaction between gnome-control-center, gnome-tweak-tool, xkbd, xmodmap which are quite complex and, worst, undocumented. If you find some link please share it! (Although I suspect almost no one knows it for real. Just see at the unfixability of https://bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/1218322 ) – Rmano Feb 20 '14 at 15:16
  • What is the hyper key? – Seth Feb 21 '14 at 03:50
  • @Seth: See here: http://askubuntu.com/a/19565/216010 In my case, AutoKey recognizes the two as different keys, so if I can map right Windows to hyper, then I can have a whole new set of shortcuts with it. – Alexander Rechsteiner Feb 21 '14 at 09:33
  • @Rmano that's because keybord mapping in general is neither nice, not comprehensive, in very fundamental ways ;) – Volker Siegel Aug 03 '14 at 10:08

2 Answers2

13

For some reason Ubuntu currently assigns both Super and Hyper to Mod4. You can see this in /usr/share/X11/xkb/symbols/pc:

 key <SUPR> {   [ NoSymbol, Super_L ]   };
 modifier_map Mod4   { <SUPR> };

 key <HYPR> {   [ NoSymbol, Hyper_L ]   };
 modifier_map Mod4   { <HYPR> };

I was able to change this to put super and hyper on separate modifiers without needing to be root or modify any system files. I'm not sure if this is the best way as I am definitely not an xkb expert, but it's a way that has been reliable for me.

First, create a local symbols file. I have mine in ${HOME}/.config/xkb/symbols/local. This assigns Super to Mod3 and Hyper to Mod4.

default  partial modifier_keys
xkb_symbols "superhyper" {

    modifier_map Mod3 { Super_L, Super_R };

    key <SUPR> {    [ NoSymbol, Super_L ]   };
    modifier_map Mod3   { <SUPR> };

    key <HYPR> {    [ NoSymbol, Hyper_L ]   };
    modifier_map Mod4   { <HYPR> };
};

Then recompile the existing map to add a "local":

setxkbmap -print | sed -e '/xkb_symbols/s/"[[:space:]]/+local&/' | xkbcomp -I${HOME}/.config/xkb - ${DISPLAY}

Put this in a script to be run when you log in. You can run it as an ordinary user.

ergosys
  • 260
  • Is it possible to just edit that file in place to change HYPR to Mod3? – Alex Moore-Niemi Mar 25 '17 at 19:37
  • 3
    You can do this. The benefits of not editing in place is that a system update won't overwrite your changes. – ergosys Mar 26 '17 at 17:37
  • For myself, I had it working briefly with https://raw.githubusercontent.com/jabbalaci/dotfiles/master/.Xmodmap though it keeps mysteriously stopping... – Alex Moore-Niemi Mar 26 '17 at 17:40
  • Also a drawback of my answer's method that I've found is that if your keyboard is unplugged or loses USB communication due to a random glitch, the script must be run again. There is probably some way to rerun it automatically, but I haven't looked into it. Fortunately the random glitch thing only happens once or so a month for me. If you edit the system files this shouldn't be an issue. So there are pluses and minuses. – ergosys Mar 26 '17 at 17:45
  • how would i use xkb settings to remap caps lock to hyper key? – Alex Moore-Niemi Mar 26 '17 at 18:24
  • 2
    I use that as well. There's already a canned setup for it, so I use: setxkbmap -option 'caps:hyper' – ergosys Mar 27 '17 at 01:30
  • any idea why this doesn't work with super on mod4 and hyper on mod3? if you do that, mod4 is still super AND hyper. – Toothrot Dec 18 '18 at 16:29
  • Not really, sorry. – ergosys Dec 19 '18 at 17:14
  • Unfortunately, doesn't work for me on Ubuntu 18.04 – likern Jul 01 '19 at 17:32
  • That is indeed unfortunate. I can't help until I actually migrate past 16.04 myself, and I don't know when that will be. – ergosys Jul 02 '19 at 05:56
  • I got this working in 18.04 with gnome-tweak-tool and the process above, but after running the software updater this morning, not so much any more. – Ashton Honnecke Nov 22 '19 at 15:16
  • I got this working in 18.04 again! – Ashton Honnecke Dec 18 '19 at 16:08
  • Stopped working at some point. – Ashton Honnecke May 06 '20 at 19:35
  • I've been using this on 18.04 now for several months, no issues. So I'm afraid I don't have any solutions for those for whom it doesn't work. – ergosys May 12 '20 at 04:41
6

With xmodmap you can change this behavior with 2 commands:

## Hyper_L is mod4 by default, we will "move" it to Mod3
xmodmap -e "remove mod4 = Hyper_L"
xmodmap -e "add mod3 = Hyper_L"
Alex Stragies
  • 199
  • 1
  • 6