Choose any key as the modifier in i3wm in 6 steps

Published:
Last modified:

Overview

Guide to choose any key of your keyboard as the modifier in the i31 (improved tiling window manager).

Motivation

The modifier key is essential in the i3 window manager as it is the main way to interact with it.

For an old mechanical keyboard which has not Windows (Mod4) key to use as modifier the default choice is to use the Alt (Mod1) key, but it limits the usage in many ways as it collides with many other programs’ keybindings.

1. Key alternatives

By default there is a list of possible keys which you can choose from without much work, to get this list we use the command xmodmap, which is an “utility for modifying keymaps and pointer button mappings in X” that shows the standards modifiers understood by i3.


$ xmodmap
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

2. Choose key

We will choose a new key that is not present as a candidate by the standard modifiers, in this case the PrtScn (the Print Screen key).

For this we need to get the key identifier, using xev command (print contents of X events).

Run xev and then press the desired key, ie.: PrtScn, so xev will print that key information.


$ xev
KeyRelease event, serial 34, synthetic NO, window 0x2200001,
   root 0x9f, subw 0x0, time 16682622, (-173,425), root:(1111,445),
   state 0x0, keycode 107 (keysym 0xff61, Print), same_screen YES,
   XLookupString gives 0 bytes: 
   XFilterEvent returns: False

Now we know its keycode is 107 which will be used next.

3. Set new key as mod

We will set the mod3 modifier as the i3 modifier. For this we create a file ~/.Xmodmap:

! Print: set as modifier (mod3)
! set mod3 to Print key, so I can use it as i3 modifier
keycode 107 = Print
clear mod3
add mod3 = Print

4. Set new mod key

Load new configuration with xmodmap ~/.Xmodmap using “xmodmap - utility for modifying keymaps and pointer button mappings in X”.


$ xmodmap ~/.Xmodmap

5. Use mod in i3

In .config/i3/config we use the set command:

#set $mod Mod1
set $mod Mod3

and reload configuration with (yet) old `mod** $mod+Shift+c.

6. Persist changes

Make these changes persistent to have them on next reboot.

At the begninning of .config/i3/config add (without double quotes in its parameters):

exec --no-startup-id xmodmap /path/to/.Xmodmap

Final

Now you can use PrtScn as the new modifier for i3.

References

Uruguay
Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus


Change the default mod key for using i3 window manager in Ubuntu Linux

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme

·