swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.42k stars 1.1k forks source link

Chord key bindings #5094

Closed w96k closed 4 years ago

w96k commented 4 years ago

Is it possible to use Emacs-like keybindings in sway? If it is not possible, then I propose to implement this functionality; pressing mod-key simultaneously with keybindings is quite hard for my hands.

I can see using sxhkd as workaround , it has ; that delimits two strokes of one keybind. So when I have in config:

ctrl + t ; c
     urxvt

I need to press to keystroke, first is modifier ctrl+t pressed simultaneously, then c. Is it possible to implement this functionality using sway config file?

https://github.com/baskerville/sxhkd

Emantor commented 4 years ago

You can implement something similar using modes, althought it could be quite tedious to configure.

w96k commented 4 years ago

You can implement something similar using modes, althought it could be quite tedious to configure.

Thanks. I have basic setup, but I face another problem now. Bindings like (ctrl + t) work with program bindings at same time. Is it possible to state that sway will override all defined in config keybindings, so only sway's keybindings will be used (program keybinding will not be triggered)

Work in progress config:

set $stump Control+t

assign [class="Emacs"] number "0: Emacs"

mode "stumpwm" {

    # Launch emacs
    bindsym e exec emacs

    # Launch terminal
    bindsym --release c exec "swaymsg mode default; $term;"

    # Kill window
    bindsym k exec "swaymsg kill; swaymsg mode default;"

    # Navigation
    bindsym --release Control+p exec "swaymsg workspace prev; swaymsg mode default;"
    bindsym --release Control+n exec "swaymsg workspace next; swaymsg mode default;"
    bindsym --release n exec "swaymsg focus down; swaymsg mode default;"
    bindsym --release p exec "swaymsg focus up; swaymsg mode default;"
    bindsym --release b exec "swaymsg focus left; swaymsg mode default;"
    bindsym --release f exec "swaymsg focus right; swaymsg mode default;"
    bindsym --release t exec "swaymsg workspace current; swaymsg mode default;"
    bindsym --release Control+t exec "swaymsg workspace current; swaymsg mode default;"

    # Splitting
    bindsym --release s exec "swaymsg split vertical; swaymsg mode default;"
    bindsym --release Shift+s exec "swaymsg split horizontal; swaymsg mode default;"

    # Exit stumpwm mode
    bindsym g mode "default"
    bindsym Control+g mode "default"

    # Switch to workspace
    bindsym --release 1 exec "swaymsg workspace 1; swaymsg mode default;"
    bindsym --release 2 exec "swaymsg workspace 2; swaymsg mode default;"
    bindsym --release 3 exec "swaymsg workspace 3; swaymsg mode default;"
    bindsym --release 4 exec "swaymsg workspace 4; swaymsg mode default;"
    bindsym --release 5 exec "swaymsg workspace 5; swaymsg mode default;"
    bindsym --release 6 exec "swaymsg workspace 6; waymssg mode default;"
    bindsym --release 7 exec "swaymsg workspace 7; swaymsg mode default;"
    bindsym --release 8 exec "swaymsg workspace 8; swaymsg mode default;"
    bindsym --release 9 exec "swaymsg workspace 9; swaymsg mode default;"

    # List of windows
    bindsym w exec --no-startup-id "swaymsg mode default; rofi -show window -run-shell-command '{terminal} -e \\" {cmd}; read -n 1 -s\\"'"

}
bindsym --release $stump mode "stumpwm"

Binds are from StumpWM

Not sure that It have been written best way possible.

w96k commented 4 years ago

Thanks for your help, looks like my problem was in --release flag.