diff --git a/install.sh b/install.sh index f291941..6caa08a 100755 --- a/install.sh +++ b/install.sh @@ -154,6 +154,10 @@ backup_if_exists "$HOME/.claude/statusline.sh" backup_if_exists "$HOME/.config/lazygit/config.yml" backup_if_exists "$HOME/.config/sketchybar" backup_if_exists "$HOME/.config/yabai/yabairc" +backup_if_exists "$HOME/.config/yabai/move-window-display" +backup_if_exists "$HOME/.config/yabai/focus-window-display" +backup_if_exists "$HOME/.config/yabai/focus-window-cycle" +backup_if_exists "$HOME/.config/yabai/swap-window-cycle" backup_if_exists "$HOME/.yabairc" backup_if_exists "$HOME/.config/skhd/skhdrc" backup_if_exists "$HOME/.skhdrc" @@ -189,8 +193,12 @@ create_symlink "$DOTFILES/micro/settings.json" "$HOME/.config/micro/settings create_symlink "$DOTFILES/lazygit/config.yml" "$HOME/.config/lazygit/config.yml" chmod +x "$DOTFILES/sketchybar/sketchybarrc" "$DOTFILES/sketchybar/plugins"/*.sh create_symlink "$DOTFILES/sketchybar" "$HOME/.config/sketchybar" -chmod +x "$DOTFILES/yabai/yabairc" +chmod +x "$DOTFILES/yabai/yabairc" "$DOTFILES/yabai/move-window-display" "$DOTFILES/yabai/focus-window-display" "$DOTFILES/yabai/focus-window-cycle" "$DOTFILES/yabai/swap-window-cycle" create_symlink "$DOTFILES/yabai/yabairc" "$HOME/.config/yabai/yabairc" +create_symlink "$DOTFILES/yabai/move-window-display" "$HOME/.config/yabai/move-window-display" +create_symlink "$DOTFILES/yabai/focus-window-display" "$HOME/.config/yabai/focus-window-display" +create_symlink "$DOTFILES/yabai/focus-window-cycle" "$HOME/.config/yabai/focus-window-cycle" +create_symlink "$DOTFILES/yabai/swap-window-cycle" "$HOME/.config/yabai/swap-window-cycle" create_symlink "$DOTFILES/yabai/yabairc" "$HOME/.yabairc" create_symlink "$DOTFILES/skhd/skhdrc" "$HOME/.config/skhd/skhdrc" create_symlink "$DOTFILES/skhd/skhdrc" "$HOME/.skhdrc" diff --git a/skhd/skhdrc b/skhd/skhdrc index e21de00..916b080 100644 --- a/skhd/skhdrc +++ b/skhd/skhdrc @@ -1,16 +1,20 @@ # Leader = option + command. # Focus ventanas -alt + cmd - left : yabai -m window --focus west || yabai -m window --focus prev || true -alt + cmd - down : yabai -m window --focus south || yabai -m window --focus next || true -alt + cmd - up : yabai -m window --focus north || yabai -m window --focus prev || true -alt + cmd - right : yabai -m window --focus east || yabai -m window --focus next || true +alt + cmd - left : ~/.config/yabai/focus-window-display west || true +alt + cmd - down : ~/.config/yabai/focus-window-display south || true +alt + cmd - up : ~/.config/yabai/focus-window-display north || true +alt + cmd - right : ~/.config/yabai/focus-window-display east || true +ctrl + alt - h : ~/.config/yabai/focus-window-display west || true +ctrl + alt - j : ~/.config/yabai/focus-window-display south || true +ctrl + alt - k : ~/.config/yabai/focus-window-display north || true +ctrl + alt - l : ~/.config/yabai/focus-window-display east || true # Mover ventanas dentro del layout -alt + cmd + shift - left : yabai -m window --warp west || yabai -m window --swap west || true -alt + cmd + shift - down : yabai -m window --warp south || yabai -m window --swap south || true -alt + cmd + shift - up : yabai -m window --warp north || yabai -m window --swap north || true -alt + cmd + shift - right : yabai -m window --warp east || yabai -m window --swap east || true +alt + cmd + shift - left : ~/.config/yabai/swap-window-cycle prev || true +alt + cmd + shift - down : ~/.config/yabai/swap-window-cycle next || true +alt + cmd + shift - up : ~/.config/yabai/swap-window-cycle prev || true +alt + cmd + shift - right : ~/.config/yabai/swap-window-cycle next || true # Spaces alt + cmd - 1 : yabai -m space --focus 1 || true @@ -34,6 +38,14 @@ alt + cmd + shift - 7 : yabai -m window --space 7 && yabai -m space --focus 7 || alt + cmd + shift - 8 : yabai -m window --space 8 && yabai -m space --focus 8 || true alt + cmd + shift - 9 : yabai -m window --space 9 && yabai -m space --focus 9 || true +# Mover ventana al display y seguirla +alt + cmd + ctrl - left : ~/.config/yabai/move-window-display prev || true +alt + cmd + ctrl - right : ~/.config/yabai/move-window-display next || true + +# Cambiar foco entre ventanas del display actual +alt + cmd + ctrl - up : ~/.config/yabai/focus-window-cycle prev || true +alt + cmd + ctrl - down : ~/.config/yabai/focus-window-cycle next || true + # Layout alt + cmd - f : yabai -m window --toggle float || true alt + cmd - b : yabai -m space --balance || true diff --git a/yabai/focus-window-cycle b/yabai/focus-window-cycle new file mode 100755 index 0000000..ff0f6ec --- /dev/null +++ b/yabai/focus-window-cycle @@ -0,0 +1,29 @@ +#!/bin/bash + +set -euo pipefail + +direction="${1:-}" + +case "$direction" in + next|prev) ;; + *) exit 2 ;; +esac + +current_window="$(yabai -m query --windows --window)" +current_id="$(jq -r '.id' <<<"$current_window")" +current_display="$(jq -r '.display' <<<"$current_window")" + +target_id="$(yabai -m query --windows | jq -r --argjson display "$current_display" --argjson current "$current_id" --arg direction "$direction" ' + map(select(.display == $display and ."is-visible" == true and ."is-minimized" == false and ."is-hidden" == false)) + | sort_by(.frame.x, .frame.y) + | . as $windows + | ($windows | map(.id) | index($current)) as $idx + | if length < 2 or $idx == null then empty + elif $direction == "prev" then $windows[(($idx - 1 + length) % length)].id + else $windows[(($idx + 1) % length)].id + end +')" + +if [[ -n "$target_id" ]]; then + yabai -m window --focus "$target_id" +fi diff --git a/yabai/focus-window-display b/yabai/focus-window-display new file mode 100755 index 0000000..fc660f0 --- /dev/null +++ b/yabai/focus-window-display @@ -0,0 +1,38 @@ +#!/bin/bash + +set -euo pipefail + +direction="${1:-}" + +case "$direction" in + west|south|north|east) ;; + *) exit 2 ;; +esac + +current_window="$(yabai -m query --windows --window)" +current_id="$(jq -r '.id' <<<"$current_window")" +current_display="$(jq -r '.display' <<<"$current_window")" + +if yabai -m window --focus "$direction" 2>/dev/null; then + focused_display="$(yabai -m query --windows --window | jq -r '.display')" + if [[ "$focused_display" == "$current_display" ]]; then + exit 0 + fi + + yabai -m window --focus "$current_id" 2>/dev/null || true +fi + +target_id="$(yabai -m query --windows | jq -r --argjson display "$current_display" --argjson current "$current_id" ' + map(select(.display == $display and ."is-visible" == true and ."is-minimized" == false and ."is-hidden" == false)) + | sort_by(.frame.x, .frame.y) + | . as $windows + | ($windows | map(.id) | index($current)) as $idx + | if length < 2 or $idx == null then empty + elif "'$direction'" == "west" or "'$direction'" == "north" then $windows[(($idx - 1 + length) % length)].id + else $windows[(($idx + 1) % length)].id + end +')" + +if [[ -n "$target_id" ]]; then + yabai -m window --focus "$target_id" +fi diff --git a/yabai/move-window-display b/yabai/move-window-display new file mode 100755 index 0000000..7b1c74a --- /dev/null +++ b/yabai/move-window-display @@ -0,0 +1,36 @@ +#!/bin/bash + +set -euo pipefail + +direction="${1:-}" + +if [[ "$direction" != "next" && "$direction" != "prev" ]]; then + exit 2 +fi + +current_display="$(yabai -m query --windows --window | jq -r '.display')" + +case "$direction:$current_display" in + next:1) target_display=2 ;; + next:2) target_display=3 ;; + next:3) target_display=4 ;; + next:4) target_display=1 ;; + prev:1) target_display=4 ;; + prev:2) target_display=1 ;; + prev:3) target_display=2 ;; + prev:4) target_display=3 ;; + *) exit 1 ;; +esac + +target_space="$(yabai -m query --spaces | jq -r --argjson display "$target_display" ' + map(select(.display == $display and ."is-native-fullscreen" == false)) + | (map(select(."is-visible" == true))[0] // map(select(.type == "bsp"))[0] // .[0]) + | .index // empty +')" + +if [[ -z "$target_space" ]]; then + yabai -m window --display "$target_display" --focus + exit 0 +fi + +yabai -m window --space "$target_space" --focus diff --git a/yabai/swap-window-cycle b/yabai/swap-window-cycle new file mode 100755 index 0000000..d9c3dce --- /dev/null +++ b/yabai/swap-window-cycle @@ -0,0 +1,29 @@ +#!/bin/bash + +set -euo pipefail + +direction="${1:-}" + +case "$direction" in + next|prev) ;; + *) exit 2 ;; +esac + +current_window="$(yabai -m query --windows --window)" +current_id="$(jq -r '.id' <<<"$current_window")" +current_display="$(jq -r '.display' <<<"$current_window")" + +target_id="$(yabai -m query --windows | jq -r --argjson display "$current_display" --argjson current "$current_id" --arg direction "$direction" ' + map(select(.display == $display and ."is-visible" == true and ."is-minimized" == false and ."is-hidden" == false and ."is-floating" == false)) + | sort_by(.frame.x, .frame.y) + | . as $windows + | ($windows | map(.id) | index($current)) as $idx + | if length < 2 or $idx == null then empty + elif $direction == "prev" then $windows[(($idx - 1 + length) % length)].id + else $windows[(($idx + 1) % length)].id + end +')" + +if [[ -n "$target_id" ]]; then + yabai -m window --swap "$target_id" +fi