Gnome, Cinnamon, and KDE all use xkb
to manage keyboard mappings.
For Gnome, you use gnome-tweak-tool
to access all of the xkb
options.
I'm working on Ubuntu 21.04 using Gnome 38.8.5, so all of my xkb
files are under /usr/share/X11/xkb
. Consult your distro's documentation if this is not the case for you.
The first file we're going to be working with is an addition, under symbols
in that xkb
folder. It should already have a bunch of files like us
and dvp
etc. We're going to be adding a new file called hyper
. So on my computer, this is /usr/share/X11/xkb/symbols/hyper
.
The contents of hyper
will be this:
partial modifier_keys
xkb_symbols "ralt" {
key <RALT> { [ Hyper_R ] };
modifier_map Mod3 { <HYPR>, Hyper_R };
};
partial modifier_keys
xkb_symbols "rwin" {
key <RWIN> { [ Hyper_R ] };
modifier_map Mod3 { <HYPR>, Hyper_R };
};
partial modifier_keys
xkb_symbols "rctl" {
key <RCTL> { [ Hyper_R ] };
modifier_map Mod3 { <HYPR>, Hyper_R };
};
Now, all the other files we're working with will be up a level in /usr/share/X11/xkb/rules/
.
The first file to change is /usr/share/X11/xkb/rules/evdev
. In evdev
, all the way at the bottom, right below the line with lv5:rwin_switch_lock_cancel
and above the section that starts with ! option = compat
we're going to add three things to match the symbols we just introduced.
hyper:ralt = +hyper(ralt)
hyper:rwin = +hyper(rwin)
hyper:rctl = +hyper(rctl)
So it should look something like this:
lv5:lsgt_switch_lock_cancel = +level5(lsgt_switch_lock_cancel)
lv5:ralt_switch_lock_cancel = +level5(ralt_switch_lock_cancel)
lv5:lwin_switch_lock_cancel = +level5(lwin_switch_lock_cancel)
lv5:rwin_switch_lock_cancel = +level5(rwin_switch_lock_cancel)
hyper:ralt = +hyper(ralt)
hyper:rwin = +hyper(rwin)
hyper:rctl = +hyper(rctl)
! option = compat
grp_led:num = +lednum(group_lock)
grp_led:caps = +ledcaps(group_lock)
grp_led:scroll = +ledscroll(group_lock)
japan:kana_lock = +japan(kana_lock)
Now, we need to add descriptions to these things.
So open up the file /usr/share/X11/xkb/rules/evdev.lst
, and aaaaalll the way at the bottom (just below the terminate:ctrl_alt_bksp
, add the following:
hyper Position of the Hyper key
hyper:ralt Right Alt as Hyper
hyper:rwin Right Windows key as Hyper
hyper:rctl Right Ctrl as Hyper
So now, we have our actions, our keyword-to-internal mapping, and a descriptions. But we still need to make these options available to the gui. So the next file to edit is /usr/share/X11/xkb/rules/evdev.xml
.
Again, all the way at the bottom, before the last </optionList>
and </xkbConfigRegistry>
we're going to insert a new group
node.
<group allowMultipleSelection="true">
<configItem>
<name>Hyper</name>
<description>Position of the Hyper key</description>
</configItem>
<option>
<configItem>
<name>hyper:ralt</name>
<description>Right Alt as Hyper</description>
</configItem>
</option>
<option>
<configItem>
<name>hyper:rwin</name>
<description>Right Windows key as Hyper</description>
</configItem>
</option>
<option>
<configItem>
<name>hyper:rctl</name>
<description>Right Ctrl as Hyper</description>
</configItem>
</option>
</group>
And that's it!
You should now be able to open up your keyboard settings of choice and enable your hyper key to be any (or all) of those options under "Position of the Hyper Key".
Happy hacking!