Skip to content

Commit 84379a4

Browse files
committed
feat(yabai): pull focused windows to active space
Generated-by: aiautocommit
1 parent 9b31ec0 commit 84379a4

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# Bring a just-focused window onto the active Space and stay there.
3+
#
4+
# `yabai -m window --space mouse` alone loses two races:
5+
# 1. macOS still auto-swooshes to the window's old (now empty) Space
6+
# 2. with a second display, `mouse` may be the other screen
7+
#
8+
# YABAI_WINDOW_ID is set by the window_focused signal.
9+
10+
export PATH="/opt/homebrew/bin:/usr/bin:/bin"
11+
12+
win="${YABAI_WINDOW_ID:-}"
13+
[ -n "$win" ] || exit 0
14+
15+
dest=$(yabai -m query --spaces --space | jq -r '.index')
16+
ws=$(yabai -m query --windows --window "$win" | jq -r '.space')
17+
18+
# Already on the Space we're working on (click / Cmd-Tab same Space).
19+
[ "$ws" = "$dest" ] && exit 0
20+
21+
yabai -m window "$win" --space "$dest" 2>/dev/null
22+
yabai -m space --focus "$dest" 2>/dev/null
23+
yabai -m window --focus "$win" 2>/dev/null
24+
25+
# Auto-swoosh can finish after this signal; re-assert the destination.
26+
(
27+
sleep 0.15
28+
yabai -m space --focus "$dest" 2>/dev/null
29+
yabai -m window --focus "$win" 2>/dev/null
30+
) &

0 commit comments

Comments
 (0)