workspace/arch-user/bin/sway/focus-cousin.sh
2025-09-22 22:19:32 +00:00

18 lines
424 B
Bash
Executable File

#!/bin/bash
parent_has_sibl=$(swaymsg -t get_tree | jq '
def find_focused_path:
if .focused then [.]
elif .nodes then
[.] + (.nodes[] | find_focused_path | select(length > 0))
else empty
end;
find_focused_path | if length >= 3 and .[-2].type=="con" then 1 else 0 end
')
if [ "$parent_has_sibl" = 1 ]; then
swaymsg "focus parent; focus $1 sibling; focus child"
else
swaymsg "focus $1 sibling; focus child"
fi