The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

stay in mode only while key is pressed

asked 2015-02-06 03:21:50 +0000

kzsh gravatar image

I've started using modes

mode "foo" {
    bindsym x exec foo
    bindsym y exec bar
    bindsym z exec baz
    bindsym Escape mode "default"
}
bindcode 108 mode "vim"

and this is very nice. However, I would like to enter the mode foo only while a key is pressed. That is, I would like x,y and z to execute foo, bar and baz only while key 108 is held. Is this possible? Am I understanding modes poorly?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-02-09 12:58:08 +0000

Adaephon gravatar image

updated 2015-05-04 13:28:18 +0000

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.

edit flag offensive delete link more

Comments

Your point about not even needing modes is excellent! Thanks!

kzsh gravatar imagekzsh ( 2015-02-09 13:35:20 +0000 )edit
2

There is an error in "bindsym --release 108", it should be bindcode. The detail about Alt+another key is very interesting.

teto gravatar imageteto ( 2015-05-04 11:05:17 +0000 )edit

@teto That is, of course, correct. I fixed it now.

Adaephon gravatar imageAdaephon ( 2015-05-04 13:28:51 +0000 )edit

@Adaephon: Thanks! Great discussion of the current situation.

i3convert gravatar imagei3convert ( 2015-05-04 19:16:38 +0000 )edit

I'd love to use Win+R to enter the window resizing mode, use arrows to resize my window (with Win still pressed), and exit the resizing mode by releasing Win. This seems impossible right now. Would it make sense to request this as a new feature? xev detects all necessary keystrokes.

i3convert gravatar imagei3convert ( 2015-05-04 19:19:31 +0000 )edit

Question Tools

Stats

Asked: 2015-02-06 03:21:50 +0000

Seen: 282 times

Last updated: May 04