i3 mod key

[linkstandalone]

In my previous blog about i3wm, I had quickly mentioned that you can set the modifier key in your i3 config file with set $mod mod4 and later call $mod for your follwing bindsym keybindings. Remember, this modifier key will tell your computer that you are communicating with i3 as opposed to some other application. Generally people use the super key; this is the one that usually comes a Microsoft symbol on windows computer. This is because Linux doesn't have a general use for this key unless otherwise declared by your desktop environment.

Some people opt to use the alt key(s) because they are close to the space bar and are easy to quickly hit with your thumb. But, in the case where you are using the alt key for your modifier, you will conflict with any menu bar tool tips or alt key character entry commands. For instance, you can navigate menu items in GUI application using your keyboard instead of your mouse. As an example, you can open a new project in GIMP with the key presses of alt+f followed by n. Here is what those alt key tool tips look like in GIMP, when activated:

Example of alt-key tool tips in GIMP

Thus it may be worthwhile to swap the location of the alt and super keys on your keyboard. I have accomplished this using a program called xmodmap (xorg-xmodmap) The arch wiki provides some general guidance on how you could accomplish this, but I'll go in more detail here. In short, I have written this script, and it works to solve the issue by simply calling it when I start i3:


#!/bin/sh
xmodmap -e "clear mod1"
xmodmap -e "clear mod4"
xmodmap -e "keycode 133 = Alt_L"
xmodmap -e "keycode 64 = Super_L"
xmodmap -e "keycode 108 = Super_R"
xmodmap -e "add mod1 = Alt_L Alt_R"
xmodmap -e "add mod4 = Super_L Super_R"

And in my i3 config, exec /path/to/keyboard/script.sh

Note this is different from using a .Xmodmap dotfile in my home directory. I do this because unplugging or making changes to your keyboard can reset your configuration, and it is easier to simply rerun the script again than to source the dotfile with xmodmap ~/.Xmodmap.

In short, what is being done here is a series of commands telling xmodmap to execute a process. The script erases the existing series of keysyms that are bound to the mod1 and mod4, assigns keysyms to a specific keycode, and reassigns the mod1/mod4 modifiers with the new keysyms. You can see the existing list of keycodes and their associated keysyms with xmodmap -pke and which keysyms are bound to specific modifiers with xmodmap -pm. It may be useful to pipe the results to a grep command to select out those that mention alt or super, etc. For me, this involved keycodes 133, 64, and 108, although that may differ on different keyboards. On the other hand, this remains true on all of the computers I own.