It is somewhat possible but there are side-effects when binding the mode to modifier keys.
Do you really need modes for that?
As the key with the code 108 usually is a modifier key (depending on your keyboard layout either right Alt [Mod1
] or Alt-Gr [Mod5
]) it will not work smoothly. But why not just bind the key combination explicitly? Assuming it is the right Alt key on the US keyboard layout:
bindsym Mod1+x exec foo
bindsym Mod1+y exec bar
bindsym Mod1bz exec baz
Yes, I really want to use modes!
1. Modes on modifier keys
You can bind to the release of a key instead of the default press by using bindsym --release
or bindcode --release
. So something like this
mode "foo" {
bindcode --release 108
}
bindcode 108
would switch into modo "foo" when pressing "Alt" (on US layout) and leaving it again when releasing the key. (Note: it does not seem to work the very first time after loading the configuration)
Of course, just switching modes does not really help anything and so you need to set additional bindings. As key 108 is a modifier key, and will be pressed while the mode is open, it will affect any key pressed during that time. So you have to set the key bindings with that modifier (again assuming US layout):
mode "foo" {
bindsym Mod1+x exec foo
bindsym Mod1+y exec bar
bindsym Mod1+z exec baz
bindcode --release 108
bindsym Escape mode "default"
}
bindcode 108 mode "foo"
This basically does work: The mode will be entered and the key bindings become only available if the right Alt key is used (really the only advantage I can see compared to the mode-less solution above) and you can start the programs with the respective keys. But when the Alt key is used in a key combination (that is by actually pressing Alt+x), its release will not be registered by i3 and the mode "foo" will remain active until pressing and releasing key 108 again (or by pressing Escape).
This seems to be the case for all modifier keys.
2. Modes on non-modifier keys
Keys that are not modifiers seem to work better and are more straight-forward to set up. Of course for that you need some keys that you do not need otherwise, for example multimedia keys.
For example, on my keyboard I have a key labeled "Print" with code 218 (which is not identical to the key with the code 107, which can usually be found in the 3-key cluster to the right of the function keys). Using that key I set up the following:
mode "foo" {
bindcode --release 218 mode "default"
bindsym x exec foo
bindsym y exec bar
bindsym z exec baz
}
bindcode 218 mode "foo"
and it seemed to work just fine, without the problems I experienced when using modifier keys.