2

I have several "lesser" modes in my i3 config, which only have a few keybindings for specific tasks. For example, Skype mode:

mode "skype" {
        bindsym $mod+1 exec xdotool mousemove 90 70; exec xdotool click 1
        bindsym $mod+2 exec xdotool mousemove 90 110; exec xdotool click 1
        bindsym $mod+3 exec xdotool mousemove 90 150; exec xdotool click 1
        bindsym $mod+4 exec xdotool mousemove 90 190; exec xdotool click 1
        bindsym $mod+5 exec xdotool mousemove 90 230; exec xdotool click 1
        bindsym $mod+6 exec xdotool mousemove 90 270; exec xdotool click 1
        bindsym $mod+7 exec xdotool mousemove 90 310; exec xdotool click 1
        bindsym $mod+8 exec xdotool mousemove 90 350; exec xdotool click 1
        bindsym $mod+9 exec xdotool mousemove 90 390; exec xdotool click 1
        bindsym $mod+0 exec xdotool mousemove 90 430; exec xdotool click 1

        ...
}

which changes Alt+numbers to switch Skype chats instead of workspaces.

However, while in Skype mode, I can no longer use the other keybindings I've set up in my .i3/config (such as Alt+hjkl, dmenu, and most notably the brightness, volume, and PrtSc keys).

I'd rather not copy every single one of the bindsyms and bindcodes from the default mode into each and every one of my other modes, which would result in an unmaintainable mess1. Is there any way to "inherit" keybindings from the default mode to another?

1: well, the hardcoded pixel values for Skype mode already are an unmaintainable mess, but I'd rather not make it even more so. ;)

1

As it is clear that there is no "vanilla" i3 way to do this, I have created a small preprocessor called i3bang that allows me to achieve this.

Simply

  1. Download and set up i3bang.

  2. Wrap all of your keybindings in default mode like so:

    !@<+default_keybindings
    bindsym ...
    >
    
  3. Now include a reference to that section at the end of the mode you would like to keep default keybindings in:

    mode "skype" {
            bindsym $mod+!!1..9,0 exec xdotool mousemove 90 !<70+40*!!<0..9>>; \
                                  exec xdotool click 1
            ...
            !@default_keybindings
    }
    

    Since i3 (somewhat unintuitively) uses the first occurrence of a binding to a certain key if there are multiple bindings that use the same key, putting the reference to default_keybindings last means that any conflicting keybindings in your new mode will override the default.

Full disclosure: in case it isn't clear enough already, this is my own tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.