From 820d96f43f5bc45fca8eb14a13295a38d948e0a8 Mon Sep 17 00:00:00 2001 From: "dividend.solo" <38703245+dividendsolo@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:22:46 -0500 Subject: [PATCH] Omarchy 4.5 window fixes: terminal in the focused folder, centred float on a monitor move, Bitwarden floats (#39) alt-enter runs bin/omarchy-terminal: Ghostty opens in the folder of the focused terminal's shell (the shell on a pty of its own, under the app's login or as session leader), else in HOME (omacom/omarchy#15007). cmd-ctrl-shift-arrow runs bin/omarchy-move-to-monitor, which centres a floating window on the monitor it lands on via Hammerspoon (#14549). Bitwarden and 1Password 7 float (#11704); the float rules are listed at their head. Floating workspaces (#16143) and the backward window cycle (#8576) already behave in AeroSpace; tests hold both. --- CHANGELOG.md | 11 +++ README.md | 4 +- aerospace/aerospace.toml | 42 +++++++-- bin/omarchy-move-to-monitor | 21 +++++ bin/omarchy-terminal | 37 ++++++++ hammerspoon/init.lua | 4 +- tests/window-fixes-test.sh | 156 +++++++++++++++++++++++++++++++++ tests/workspace-layout-test.sh | 11 +++ 8 files changed, 277 insertions(+), 9 deletions(-) create mode 100755 bin/omarchy-move-to-monitor create mode 100755 bin/omarchy-terminal create mode 100755 tests/window-fixes-test.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 02e7183..fb6aff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ maintainer's Mac runs from a clone of it, the same as yours. ## 2026-11-11 +- Omarchy 4.5's window fixes (#39). ⌥↩ opens the new Ghostty window in the + folder of the focused terminal's shell, and in your home folder when the + focused app is not a terminal (a browser's download helper no longer sends + it to Downloads). ⌘⌃⇧arrow centres a floating window on the monitor it + moves to, instead of keeping its offset from the old monitor's corner. + Bitwarden and 1Password 7 float like 1Password 8, and the head of the float + rules in `aerospace.toml` lists every app that floats. A floating workspace + (⌥L) never takes a window a float rule floats, and ⌘⌥⇧` already cycles back + through every window, floating ones too; tests now hold both. Rerun + `install.sh` once after the pull: it links the two new scripts, + `omarchy-terminal` and `omarchy-move-to-monitor`. - Menu fixes from Omarchy 4.5. An installed item stays in the menu, dimmed and marked "✓ installed" (Install > Service > Slack), instead of looking like one more thing to install. Setup > Defaults > Agent installs a missing diff --git a/README.md b/README.md index 9b8a1f7..6f7ef4a 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ is also available. | Keys | Action | |---|---| -| ⌥↩ | Ghostty (terminal) | +| ⌥↩ | Ghostty (terminal), in the focused terminal's folder, else in your home folder | | ⌘⌥↩ | Ghostty + tmux (attaches to the session "Work", or makes it) | | ⌘⌃↩ | Ghostty + herdr (agent multiplexer) | | ⌘⇧↩ | Browser (macOS default) | @@ -186,7 +186,7 @@ is also available. |---|---| | ⌘⇧←/↓/↑/→ | Swap window in direction | | ⌘⇧⌥←/→/↑/↓ | Move workspace to prev / next monitor | -| ⌘⌃⇧←/↓/↑/→ | Move focused window across monitors | +| ⌘⌃⇧←/↓/↑/→ | Move focused window across monitors (a floating one lands centred) | ### Workspaces diff --git a/aerospace/aerospace.toml b/aerospace/aerospace.toml index 432463d..f6a484a 100644 --- a/aerospace/aerospace.toml +++ b/aerospace/aerospace.toml @@ -141,10 +141,12 @@ cmd-shift-alt-down = 'move-workspace-to-monitor --wrap-around next' # ---------- Move just the focused window across monitors ---------- # (swap within workspace = cmd-shift-arrow; whole workspace = cmd-shift-alt-arrow) -cmd-ctrl-shift-left = 'move-node-to-monitor --wrap-around --focus-follows-window left' -cmd-ctrl-shift-right = 'move-node-to-monitor --wrap-around --focus-follows-window right' -cmd-ctrl-shift-up = 'move-node-to-monitor --wrap-around --focus-follows-window up' -cmd-ctrl-shift-down = 'move-node-to-monitor --wrap-around --focus-follows-window down' +# A floating window is centred on the monitor it lands on (Omarchy 4.5), see +# bin/omarchy-move-to-monitor. +cmd-ctrl-shift-left = 'exec-and-forget $HOME/.local/bin/omarchy-move-to-monitor left' +cmd-ctrl-shift-right = 'exec-and-forget $HOME/.local/bin/omarchy-move-to-monitor right' +cmd-ctrl-shift-up = 'exec-and-forget $HOME/.local/bin/omarchy-move-to-monitor up' +cmd-ctrl-shift-down = 'exec-and-forget $HOME/.local/bin/omarchy-move-to-monitor down' # ---------- Resize ---------- alt-equal = 'resize smart +50' @@ -158,6 +160,8 @@ ctrl-alt-shift-tab = 'focus-monitor --wrap-around prev' # ---------- Cycle windows within workspace ---------- # cmd-backtick and cmd-shift-backtick are the Quake consoles (hammerspoon/init.lua). +# Omarchy's Alt+Tab / Alt+Shift+Tab. The DFS order counts floating windows too, +# so both ways reach every window (no z-order to ping-pong on, as Hyprland's had). cmd-alt-backtick = 'focus --boundaries-action wrap-around-the-workspace dfs-next' cmd-alt-shift-backtick = 'focus --boundaries-action wrap-around-the-workspace dfs-prev' @@ -165,7 +169,9 @@ cmd-alt-shift-backtick = 'focus --boundaries-action wrap-around-the-workspace df # The browser and web apps follow the macOS default browser (v4.0.5), through # bin/omarchy-launch-browser. Web apps are app windows (`--app=`) in a # Chromium browser: a window of their own that tiles, not a tab. -alt-enter = 'exec-and-forget open -na Ghostty' +# A new terminal opens in the focused terminal's folder, else in $HOME (Omarchy +# 4.5), see bin/omarchy-terminal. +alt-enter = 'exec-and-forget $HOME/.local/bin/omarchy-terminal' cmd-alt-enter = 'exec-and-forget open -na Ghostty --args -e /bin/zsh -lc "tmux attach -t Work || tmux new -s Work"' cmd-ctrl-enter = 'exec-and-forget open -na Ghostty --args -e herdr' cmd-shift-enter = 'exec-and-forget $HOME/.local/bin/omarchy-launch-browser' @@ -266,6 +272,22 @@ cmd-shift-down = ['join-with down', 'mode main'] cmd-shift-up = ['join-with up', 'mode main'] cmd-shift-right = ['join-with right', 'mode main'] +# Float rules: every app whose windows open floating. A workspace in floating +# mode (alt-l) never claims these, so they stay floating when it ends. +# System Settings com.apple.systempreferences +# Finder com.apple.finder +# 1Password 8 and 7 com.1password.1password, com.agilebits.onepassword7 +# Bitwarden com.bitwarden.desktop +# Raycast com.raycast.macos +# Activity Monitor com.apple.ActivityMonitor +# Calculator com.apple.calculator +# Preview com.apple.Preview +# VLC org.videolan.vlc +# Steam com.valvesoftware.steam +# LocalSend org.localsend.localsendApp +# Picture in Picture (any app, by window title) +# The screensaver com.mitchellh.ghostty, title org.omarchy.screensaver + [[on-window-detected]] if.app-id = 'com.apple.systempreferences' run = 'layout floating' @@ -274,10 +296,20 @@ run = 'layout floating' if.app-id = 'com.apple.finder' run = 'layout floating' +# Password managers float, like Omarchy's 1password.lua (omacom/omarchy#11704) +# and bitwarden.lua. [[on-window-detected]] if.app-id = 'com.1password.1password' run = 'layout floating' +[[on-window-detected]] +if.app-id = 'com.agilebits.onepassword7' +run = 'layout floating' + +[[on-window-detected]] +if.app-id = 'com.bitwarden.desktop' +run = 'layout floating' + [[on-window-detected]] if.app-id = 'com.raycast.macos' run = 'layout floating' diff --git a/bin/omarchy-move-to-monitor b/bin/omarchy-move-to-monitor new file mode 100755 index 0000000..d44d518 --- /dev/null +++ b/bin/omarchy-move-to-monitor @@ -0,0 +1,21 @@ +#!/bin/bash +# Super+Ctrl+Shift+arrow: move the focused window to the next monitor that +# way. AeroSpace keeps a floating window's offset from the monitor's corner, +# so on a monitor of another size it lands off-centre or partly off screen; +# Omarchy 4.5 centres it there (omacom/omarchy#14549), and so does this. +# A tiled window needs nothing: AeroSpace tiles it on the new monitor. +# +# omarchy-move-to-monitor left|right|up|down +set -u +AS="${AEROSPACE:-aerospace}" +HS="${HS:-hs}" + +"$AS" move-node-to-monitor --wrap-around --focus-follows-window "$1" || exit +read -r id layout screen < <("$AS" list-windows --focused \ + --format '%{window-id} %{window-layout} %{monitor-appkit-nsscreen-screens-id}') +[[ ${layout:-} == floating ]] || exit 0 +# Both go into Lua source below, so only plain numbers pass. +[[ $id =~ ^[0-9]+$ && $screen =~ ^[0-9]+$ ]] || exit 0 +# An AeroSpace window id is the macOS window number Hammerspoon uses, and the +# screen id is the 1-based index in NSScreen.screens (hs.screen.allScreens). +"$HS" -c "local w, s = hs.window.get($id), hs.screen.allScreens()[$screen]; if w and s then w:centerOnScreen(s, true, 0) end" diff --git a/bin/omarchy-terminal b/bin/omarchy-terminal new file mode 100755 index 0000000..6c30a2c --- /dev/null +++ b/bin/omarchy-terminal @@ -0,0 +1,37 @@ +#!/bin/bash +# Super+Return (alt-enter): a new Ghostty window in the folder of the focused +# terminal's shell, like Omarchy's omarchy-cmd-terminal-cwd. Any other app +# gets a terminal in $HOME (Omarchy 4.5, omacom/omarchy#15007): a browser's +# helper shell sitting in ~/Downloads is not a terminal's shell. +# +# A terminal starts its shell on a pty of its own, as the session leader or +# (Ghostty on macOS) as the child of a `login` that leads the session. A +# helper shell another app spawns has no pty, or shares the app's. +# +# shortcut: an app with several windows (Ghostty tabs) gives its newest shell, +# as Omarchy does; the focused tab's shell needs the terminal's own API. +set -u +AS="${AEROSPACE:-aerospace}" + +app=$("$AS" list-windows --focused --format '%{app-pid}' 2>/dev/null) +dir="" +if [[ -n $app ]]; then + shells=" $(grep -v '^#' /etc/shells | sed 's|.*/||' | tr '\n' ' ') " + pid=$(ps -Ao pid=,ppid=,stat=,tty=,comm= | awk -v app="$app" -v shells="$shells" ' + { n = $5; sub(/^-/, "", n); sub(/.*\//, "", n) + pids[NR] = $1; ppid[$1] = $2; stat[$1] = $3; tty[$1] = $4; name[$1] = n } + END { + for (i = 1; i <= NR; i++) { + p = pids[i] + if (index(shells, " " name[p] " ") == 0 || tty[p] == "??" || tty[p] == tty[app]) continue + lead = (stat[p] ~ /s/) ? p : ppid[p] + if (stat[lead] !~ /s/ || ppid[lead] != app) continue + if (p + 0 > best + 0) best = p + } + print best + }') + [[ -n $pid ]] && dir=$(lsof -a -p "$pid" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -n1) +fi +[[ -n $dir && -d $dir ]] || dir=$HOME + +exec open -na Ghostty --args --working-directory="$dir" diff --git a/hammerspoon/init.lua b/hammerspoon/init.lua index 943a396..83d972f 100644 --- a/hammerspoon/init.lua +++ b/hammerspoon/init.lua @@ -13,7 +13,7 @@ local bindings = { { "SUPER + SPACE", "Raycast" }, { "ALT + SPACE", "Dictation on / off (Hex)" }, { "hold RIGHT ALT", "Dictate while held (Hex)" }, - { "ALT + RETURN", "Ghostty (terminal)" }, + { "ALT + RETURN", "Ghostty (terminal) in the focused folder" }, { "SUPER + ALT + RETURN", "Ghostty + tmux (Work)" }, { "SUPER + CTRL + RETURN", "Ghostty + herdr" }, { "SUPER + SHIFT + RETURN", "Browser (macOS default)" }, @@ -73,7 +73,7 @@ local bindings = { { "ALT + TAB", "Next workspace on this monitor" }, { "SUPER + CTRL + TAB", "Back-and-forth between workspaces" }, { "SUPER + SHIFT + ALT + ←/→/↑/↓", "Move workspace to prev/next monitor" }, - { "SUPER + CTRL + SHIFT + ←/↓/↑/→", "Move focused window across monitors" }, + { "SUPER + CTRL + SHIFT + ←/↓/↑/→", "Move focused window across monitors (floats centre)" }, -- Resize { "ALT + =", "Grow focused window" }, diff --git a/tests/window-fixes-test.sh b/tests/window-fixes-test.sh new file mode 100755 index 0000000..1ed561a --- /dev/null +++ b/tests/window-fixes-test.sh @@ -0,0 +1,156 @@ +#!/bin/bash +# Checks the Omarchy 4.5 window fixes (#39) with fake `aerospace`, `ps`, +# `lsof`, `open` and `hs` on PATH, so nothing on the Mac moves: +# - ⌥↩ (bin/omarchy-terminal) opens Ghostty in the focused terminal's folder, +# and in $HOME for any other app (omacom/omarchy#15007); +# - ⌘⌃⇧arrow (bin/omarchy-move-to-monitor) centres a floating window on the +# monitor it lands on (omacom/omarchy#14549); +# - 1Password and Bitwarden float (omacom/omarchy#11704), and the float +# rules are listed in aerospace.toml; +# - ⌘⌥⇧` cycles back through every window, floating ones too +# (omacom/omarchy#8576). +# +# tests/window-fixes-test.sh +set -u +HERE="$(cd "$(dirname "$0")" && pwd)" +BIN="$HERE/../bin" +TOML="${AEROSPACE_TOML:-$HERE/../aerospace/aerospace.toml}" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT +fails=0 + +check() { # check + if [[ "$3" == "$2" ]]; then echo " ok $1" + else echo " FAIL $1 (expected '$2', got '$3')"; fails=$((fails + 1)); fi +} + +mkdir -p "$TMP/bin" "$TMP/home" "$TMP/project dir" +# Each fake logs its arguments and answers from a file the test writes. +cat >"$TMP/bin/aerospace" <<'SH' +#!/bin/bash +echo "aerospace $*" >>"$FAKE/log" +case "$*" in + "list-windows --focused --format %{app-pid}") cat "$FAKE/app-pid" ;; + "list-windows --focused --format "*) cat "$FAKE/focused" ;; + move-node-to-monitor*) exit "$(cat "$FAKE/move-exit")" ;; +esac +SH +cat >"$TMP/bin/ps" <<'SH' +#!/bin/bash +cat "$FAKE/ps" +SH +cat >"$TMP/bin/lsof" <<'SH' +#!/bin/bash +# lsof -a -p -d cwd -Fn +pid=$3 +echo "p$pid"; echo fcwd; grep "^$pid " "$FAKE/cwds" | cut -d' ' -f2- | sed 's/^/n/' +SH +for f in open hs; do + printf '#!/bin/bash\necho "%s $*" >>"$FAKE/log"\n' "$f" >"$TMP/bin/$f" +done +chmod +x "$TMP/bin/"* +export FAKE="$TMP" PATH="$TMP/bin:$PATH" HOME="$TMP/home" AEROSPACE="$TMP/bin/aerospace" HS="$TMP/bin/hs" +echo "500 $TMP/project dir" >"$TMP/cwds" +echo "700 $TMP/Downloads" >>"$TMP/cwds" +echo "810 $TMP/project dir" >>"$TMP/cwds" +mkdir -p "$TMP/Downloads" + +terminal() { # terminal -> the folder the new Ghostty window opens in + : >"$TMP/log" + "$BIN/omarchy-terminal" + sed -n 's/^open -na Ghostty --args --working-directory=//p' "$TMP/log" +} + +echo "omarchy-terminal:" +# Ghostty on macOS: ghostty starts login on a new pty (a session leader), +# and login starts the shell. +cat >"$TMP/ps" <<'PS' + 100 1 S ?? /Applications/Ghostty.app/Contents/MacOS/ghostty + 499 100 Ss+ ttys001 /usr/bin/login + 500 499 S+ ttys001 -zsh + 510 500 S+ ttys001 nvim +PS +echo 100 >"$TMP/app-pid" +check "a terminal's shell gives its folder" "$TMP/project dir" "$(terminal)" + +# A browser keeps a helper shell in Downloads, with no pty of its own. +cat >"$TMP/ps" <<'PS' + 200 1 S ?? /Applications/Brave.app/Contents/MacOS/Brave + 700 200 S ?? /bin/bash +PS +echo 200 >"$TMP/app-pid" +check "a browser's helper shell gives HOME" "$TMP/home" "$(terminal)" + +# The same browser started from a terminal: its helper shares that terminal's +# pty, but neither leads a session of its own. +cat >"$TMP/ps" <<'PS' + 200 500 S+ ttys001 /Applications/Brave.app/Contents/MacOS/Brave + 700 200 S+ ttys001 /bin/bash +PS +check "a browser started from a terminal gives HOME" "$TMP/home" "$(terminal)" + +# A terminal that runs the shell itself as the session leader (Linux style). +cat >"$TMP/ps" <<'PS' + 800 1 S ?? /Applications/Alacritty.app/Contents/MacOS/alacritty + 810 800 Ss+ ttys004 /bin/zsh +PS +echo 800 >"$TMP/app-pid" +check "a shell that leads its own session gives its folder" "$TMP/project dir" "$(terminal)" + +: >"$TMP/app-pid" +check "no focused window gives HOME" "$TMP/home" "$(terminal)" + +echo "omarchy-move-to-monitor:" +move() { : >"$TMP/log"; "$BIN/omarchy-move-to-monitor" "$@"; grep -v ' list-windows ' "$TMP/log" | tr '\n' ';'; } +echo 0 >"$TMP/move-exit" +echo "42 floating 2" >"$TMP/focused" +check "a floating window moves, then centres on its new monitor" \ + 'aerospace move-node-to-monitor --wrap-around --focus-follows-window right;hs -c local w, s = hs.window.get(42), hs.screen.allScreens()[2]; if w and s then w:centerOnScreen(s, true, 0) end;' "$(move right)" +echo "42 h_tiles 2" >"$TMP/focused" +check "a tiled window only moves (AeroSpace tiles it)" \ + 'aerospace move-node-to-monitor --wrap-around --focus-follows-window left;' "$(move left)" +echo 1 >"$TMP/move-exit" +echo "42 floating 1" >"$TMP/focused" +check "no other monitor: nothing is centred" \ + 'aerospace move-node-to-monitor --wrap-around --focus-follows-window up;' "$(move up)" + +key() { # key -> its main-mode command + python3 - "$TOML" "$1" <<'PY' +import sys, tomllib +print(tomllib.load(open(sys.argv[1], "rb"))["mode"]["main"]["binding"].get(sys.argv[2], "")) +PY +} + +echo "aerospace.toml:" +check "⌥↩ opens a terminal in the focused folder" \ + 'exec-and-forget $HOME/.local/bin/omarchy-terminal' "$(key alt-enter)" +for dir in left right up down; do + check "⌘⌃⇧$dir moves the window and centres a float" \ + "exec-and-forget \$HOME/.local/bin/omarchy-move-to-monitor $dir" "$(key cmd-ctrl-shift-$dir)" +done +# AeroSpace's dfs order puts floating windows in the tree (unless +# --ignore-floating), so the backward cycle reaches every window: no +# z-order to ping-pong on, as Hyprland's had. +check "⌘⌥⇧\` cycles back through every window, floating ones too" \ + 'focus --boundaries-action wrap-around-the-workspace dfs-prev' "$(key cmd-alt-shift-backtick)" +check "⌘⌥\` cycles forward the same way" \ + 'focus --boundaries-action wrap-around-the-workspace dfs-next' "$(key cmd-alt-backtick)" + +floats=$(python3 - "$TOML" <<'PY' +import sys, tomllib +for r in tomllib.load(open(sys.argv[1], "rb")).get("on-window-detected", []): + run = r["run"] if isinstance(r["run"], list) else [r["run"]] + if "layout floating" in run and "app-id" in r.get("if", {}): + print(r["if"]["app-id"]) +PY +) +for id in com.1password.1password com.agilebits.onepassword7 com.bitwarden.desktop; do + check "$id floats" 1 "$(grep -cx "$id" <<<"$floats")" +done +# The list at the head of the rules names every app-id that floats. +listed=$(sed -n '/^# Float rules:/,/^$/p' "$TOML") +missing="" +for id in $floats; do grep -qF "$id" <<<"$listed" || missing="$missing $id"; done +check "every float rule is in the list" "" "$missing" + +[[ "$fails" -eq 0 ]] && echo "PASS" || { echo "FAIL: $fails check(s)"; exit 1; } diff --git a/tests/workspace-layout-test.sh b/tests/workspace-layout-test.sh index a2159da..cd6e39c 100755 --- a/tests/workspace-layout-test.sh +++ b/tests/workspace-layout-test.sh @@ -56,6 +56,17 @@ check "floating -> tiles tiles back only the windows it floated" \ "layout --window-id 11 tiling;layout --window-id 12 tiling;layout --workspace 2 --root tiles;" "$(calls)" check "tiles is saved" tiles "$(cat "$STATE/2")" +# Omarchy 4.5 (omacom/omarchy#16143): a window a float rule floats is never the +# floating workspace's, even the first one that opens while the workspace +# floats, so leaving floating leaves it floating. +echo h_accordion >"$TMP/root" +printf '11 h_tiles\n' >"$TMP/windows" +run +printf '11 floating\n14 floating\n' >"$TMP/windows" +run +check "a window a float rule floated stays floating after floating ends" \ + "layout --window-id 11 tiling;layout --workspace 2 --root tiles;" "$(calls)" + # Super+Alt+L (Omarchy 4.5): `back` cycles the other way, tiles -> floating # -> accordion -> tiles. echo h_tiles >"$TMP/root"