746e0d032f
Today I can control "terminal" and "new" by changing the terminal alias but I always need to choose a concrete implementation, like "tmux-terminal-horizontal", even when there is otherwise no need to mention tmux in my config. Allow to configure windowing system and window placement independently by introducing dedicated options. This allows to create mappings that work in any windowing system like map global user c %{:with-option windowing_placement window new<ret>} map global user '"' %{:with-option windowing_placement vertical new<ret>} map global user '%' %{:with-option windowing_placement horizontal new<ret>} For windowing systems that don't support all placements, you can wrap the above in try/catch to fall back on the "window" variant which is defined for all windowing systems. When using multiple (nested) windowing systems, you might want to add mappings like map global user t %{:with-option windowing_module tmux new<ret>} map global user T %{:with-option windowing_module wayland new<ret>} --- This changes the default "terminal" alias for some modules. In particular, instead of delegating to iterm-terminal-vertical screen-terminal-vertical tmux-terminal-horizontal wezterm-terminal-vertical it will now by default delegate to the respective "-window" variant. We could maintain backwards compatiblity here by setting the "windowing_placement" option accordingly, but the new behavior seems more logical? Also, this removes the "terminal-tab" alias which was only defined by the kitty module. We could try to keep the alias approach and implement a "with-alias" command, however that approach can only capture both dimensions (windowing system and placement) if we add tons of commands like "terminal-horizontal" (with implied windowing system) and "tmux-terminal" (with implied placement). Side thought: we could also get rid of the "focus" alias and instead define define-command focus %{ "%opt{windowing_module}-focus" } Closes #3943, #4425
82 lines
2.6 KiB
Plaintext
82 lines
2.6 KiB
Plaintext
provide-module sway %{
|
|
|
|
# Ensure we're actually in Sway
|
|
evaluate-commands %sh{
|
|
[ -z "${kak_opt_windowing_modules}" ] ||
|
|
[ -n "$SWAYSOCK" ] ||
|
|
echo 'fail SWAYSOCK is not set'
|
|
}
|
|
|
|
require-module 'wayland'
|
|
|
|
alias global sway-terminal-window wayland-terminal-window
|
|
|
|
define-command sway-terminal-vertical -params 1.. -docstring '
|
|
sway-terminal-vertical <program> [<arguments>]: create a new terminal as a Sway window
|
|
The current pane is split into two, top and bottom
|
|
The program passed as argument will be executed in the new terminal' \
|
|
%{
|
|
nop %sh{swaymsg split vertical}
|
|
wayland-terminal-window %arg{@}
|
|
}
|
|
complete-command sway-terminal-vertical shell
|
|
|
|
define-command sway-terminal-horizontal -params 1.. -docstring '
|
|
sway-terminal-horizontal <program> [<arguments>]: create a new terminal as a Sway window
|
|
The current pane is split into two, left and right
|
|
The program passed as argument will be executed in the new terminal' \
|
|
%{
|
|
nop %sh{swaymsg split horizontal}
|
|
wayland-terminal-window %arg{@}
|
|
}
|
|
complete-command sway-terminal-horizontal shell
|
|
|
|
define-command sway-terminal-tab -params 1.. -docstring '
|
|
sway-terminal-tab <program> [<arguments>]: create a new terminal as a Sway window
|
|
The program passed as argument will be executed in the new terminal' \
|
|
%{
|
|
nop %sh{swaymsg 'split horizontal; layout tabbed'}
|
|
wayland-terminal-window %arg{@}
|
|
}
|
|
complete-command sway-terminal-tab shell
|
|
|
|
define-command sway-focus-pid -hidden %{
|
|
evaluate-commands %sh{
|
|
pid=$kak_client_pid
|
|
|
|
# Try to focus a window with the current PID, walking up the tree of
|
|
# parent processes until the focus eventually succeeds
|
|
while ! swaymsg [pid=$pid] focus > /dev/null 2> /dev/null ; do
|
|
# Replace the current PID with its parent PID
|
|
pid=$(ps -p $pid -o ppid=)
|
|
|
|
# If we couldn't get a PPID for some reason, or it's 1 or less, we
|
|
# should just fail.
|
|
if [ -z $pid ] || [ $pid -le 1 ]; then
|
|
echo "fail Can't find PID for Sway window to focus"
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
}
|
|
|
|
define-command sway-focus -params ..1 -docstring '
|
|
sway-focus [<kakoune_client>]: focus a given client''s window.
|
|
If no client is passed, then the current client is used' \
|
|
%{
|
|
# Quick branch to make sure we're calling sway-focus-pid from the client
|
|
# the user wants to focus on.
|
|
evaluate-commands %sh{
|
|
if [ $# -eq 1 ]; then
|
|
printf "evaluate-commands -client '%s' sway-focus-pid" "$1"
|
|
else
|
|
echo sway-focus-pid
|
|
fi
|
|
}
|
|
}
|
|
complete-command -menu sway-focus client
|
|
|
|
alias global focus sway-focus
|
|
|
|
}
|