Remap a Second Mod Key in niri's Config Without Extra Tools

Having a second pathway to press the default mod / super key is a nice choice to have available.
Here’s a snippet from DotFriedRice’s niri config:
xkb {
// Swap caps lock and escape.
// Remap menu key to act as an extra super / mod key.
options "caps:swapescape,altwin:menu_win"
}
The important part for this post is altwin:menu_win. The left side altwin
is the XKB category name associated with remapping the super / windows / mod
key. The right side menu_win remaps the menu key to being a Windows key. This
remaps the menu key to become a 2nd mod key. Your original mod key stays the
same.
On a lot of keyboards there’s a menu key which is usually a shortcut to right clicking the mouse. It’s often located to the right of the right alt key, or at the very least somewhere near the right side of the keyboard. It usually has 3 dashes surrounded by a rectangle.
I’ve been using computers for 25+ years and I think I pressed that key maybe twice in my life to perform a right mouse click with the keyboard. If you really like the default behavior of the menu key but want a 2nd mod key you can change the remap to use a different key.
# Why
With niri’s actions usually being tucked behind holding the mod key I sometimes found myself in situations where if I had a 2nd mod key on the right side of the keyboard that would be helpful.
Depending on where my hands are, pressing Menu+O to bring up the overview
with my right hand is comfortable and nice to have. Keep in mind you don’t need
to map Menu in niri’s config (that wouldn’t even work). The niri bind is
still Mod+O, it just so happens the menu key is now a mod key too.
The biggest use case so far has been where someone called me and I pick up the phone with my hand and now I need to look up and open a document live on the call.
With 1 hand occupied, trying to press Mod+Right or Mod+L to scroll right
with 1 hand is a big stretch, but Menu+Rightor Menu+L is a piece of cake.
The real takeaway here is niri gives you a lot of options for executing
workflows that make sense to you. 95% of the time I use the Mod key but if my
brain decided on the fly that using Menu is a more efficient pathway to do
something, now it works.
The above might seem minor but it’s not. It means the natural flow you took provided you the expected result instead of needing to be reminded that you have to make compromises on how you want to use your computer. It’s a great example of you molding your OS instead of the other way around.
# Discovering XKB Key Names
Unfortunately it’s not as easy as running wev and pressing the key to get the name. That will give you the raw key symbol but it’s not always a compatible name with niri’s xkb config.
On most Linux distros, an XKB key list does exist at
/usr/share/X11/xkb/rules/evdev.lst.
Here’s a few:
$ grep "altwin" /usr/share/X11/xkb/rules/evdev.lst
altwin Alt and Win behavior
altwin:menu Add the standard behavior to Menu key
altwin:menu_win Menu is mapped to Win
altwin:meta_alt Alt and Meta are on Alt
altwin:alt_win Alt is mapped to Win and the usual Alt
altwin:ctrl_win Ctrl is mapped to Win and the usual Ctrl
altwin:ctrl_rwin Ctrl is mapped to Right Win and the usual Ctrl
altwin:ctrl_alt_win Ctrl is mapped to Alt, Alt to Win
altwin:meta_win Meta is mapped to Win
altwin:left_meta_win Meta is mapped to Left Win
altwin:hyper_win Hyper is mapped to Win
altwin:alt_super_win Alt is mapped to Right Win, Super to Menu
altwin:swap_lalt_lwin Left Alt is swapped with Left Win
altwin:swap_ralt_rwin Right Alt is swapped with Right Win
altwin:swap_alt_win Alt is swapped with Win
altwin:prtsc_rwin Win is mapped to PrtSc and the usual Win
Funny enough the way I found this was to open the file and search for “Menu”,
that led to finding altwin:menu_win # Menu is mapped to Win which is the
exact mapping provided in the config earlier in this post.
# Demo Video
Timestamps
- 0:43 – 1 handed computing
- 1:53 – Configuring niri to remap the menu key
- 3:04 – Looking up valid XKB key names
- 4:42 – Your computer is yours
Which keyboard keys have you remapped with niri? Let us know below.