tmux only raises an activity flag for windows that are not currently
selected, so a long-running command in the window you left selected --
the common case, since you switch away by moving your Hyprland focus
elsewhere rather than by selecting another tmux window -- finished
silently and the indicator never lit.
Windows now also count as waiting when they are selected in an attached
client, every client showing them is unfocused, and their window_activity
is newer than an @omarchy_unfocused_activity watermark. The watermark is
stamped by a new `track` subcommand wired to client-focus-in/out and the
existing select-window hooks, so it records where attention last was.
The hooks pass #{window_id} and #{window_activity} as arguments, which
tmux expands when the hook fires; run-shell -b would otherwise let output
arriving during the handoff be swallowed by the new watermark. The focus
hooks take index 100 to leave a user's own bindings alone.
That state has no hook of its own, so it needs polling to be noticed.
The probe therefore moves out of the indicator and into a service plugin,
alongside nightlight and battery. A bar surface exists per monitor and
each one instantiates every indicator twice, once per block, so a timer
on the indicator meant a shell-out per instance per tick -- four probe
processes every three seconds on a two-monitor machine, forever. One
service polls for the whole shell instead.
Sharing the state also fixes what per-instance polling would have papered
over: each indicator used to own its own count, so a timer-driven update
only refreshed the bar it ran on and left the other monitors stale.
Refreshes still arrive over the existing indicator broadcast, which now
coalesces into a single run no matter how many bars relay it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CC9kSQv8ZEogaxDoeKBzL
55 lines
2.5 KiB
Bash
55 lines
2.5 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(dirname "$0")/base-test.sh"
|
|
|
|
migration="$ROOT/migrations/1784955584.sh"
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
|
|
mkdir -p "$test_dir/home/.config/tmux" "$test_dir/bin"
|
|
|
|
cat >"$test_dir/home/.config/tmux/tmux.conf" <<'EOF'
|
|
# Alerts
|
|
set-hook -g alert-bell 'run-shell -b "omarchy-shell -q omarchy.indicators refresh"'
|
|
set-hook -g after-select-window 'run-shell -b "omarchy-shell -q omarchy.indicators refresh"'
|
|
set-hook -g client-session-changed 'run-shell -b "omarchy-shell -q omarchy.indicators refresh"'
|
|
set-hook -g client-focus-out[42] 'display-message "custom focus hook"'
|
|
EOF
|
|
|
|
cat >"$test_dir/bin/omarchy-restart-tmux" <<'EOF'
|
|
#!/bin/bash
|
|
|
|
echo restart >>"$TMUX_MIGRATION_RESTART_LOG"
|
|
EOF
|
|
chmod +x "$test_dir/bin/omarchy-restart-tmux"
|
|
|
|
export TMUX_MIGRATION_RESTART_LOG="$test_dir/restarts"
|
|
tmux_config="$test_dir/home/.config/tmux/tmux.conf"
|
|
|
|
HOME="$test_dir/home" PATH="$test_dir/bin:$PATH" bash -euo pipefail "$migration" >/dev/null
|
|
|
|
grep -Fq 'after-select-window '"'"'run-shell -b "omarchy-tmux-alert track #{window_id} #{window_activity}"'"'" "$tmux_config" ||
|
|
fail "tmux activity migration tracks newly selected windows"
|
|
grep -Fq 'client-session-changed '"'"'run-shell -b "omarchy-tmux-alert track #{window_id} #{window_activity}"'"'" "$tmux_config" ||
|
|
fail "tmux activity migration tracks session changes"
|
|
grep -Fq 'client-focus-out[100] '"'"'run-shell -b "omarchy-tmux-alert track #{window_id} #{window_activity}"'"'" "$tmux_config" ||
|
|
fail "tmux activity migration tracks terminal focus loss"
|
|
grep -Fq 'client-focus-in[100] '"'"'run-shell -b "omarchy-tmux-alert track #{window_id} #{window_activity}"'"'" "$tmux_config" ||
|
|
fail "tmux activity migration tracks terminal focus gain"
|
|
grep -Fq 'client-focus-out[42] '"'"'display-message "custom focus hook"'"'" "$tmux_config" ||
|
|
fail "tmux activity migration preserves custom indexed focus hooks"
|
|
restart_count=$(wc -l <"$TMUX_MIGRATION_RESTART_LOG")
|
|
((restart_count == 1)) || fail "tmux activity migration reloads tmux once"
|
|
pass "tmux activity migration installs focus-aware hooks"
|
|
|
|
before=$(sha256sum "$tmux_config")
|
|
HOME="$test_dir/home" PATH="$test_dir/bin:$PATH" bash -euo pipefail "$migration" >/dev/null
|
|
after=$(sha256sum "$tmux_config")
|
|
|
|
[[ $before == "$after" ]] || fail "tmux activity migration is idempotent"
|
|
restart_count=$(wc -l <"$TMUX_MIGRATION_RESTART_LOG")
|
|
((restart_count == 1)) || fail "idempotent tmux activity migration does not reload tmux"
|
|
pass "tmux activity migration is idempotent"
|