Repository navigation
Set pane styles without selecting the pane (fixes focus stealing) - #6
Conversation
select-pane -P also makes the target pane the active pane, so styling a non-active pane on agent state changes moved the user's focus. The capture/restore introduced in 01b363c mitigates but doesn't eliminate it: it races with user navigation, and when the script runs without a client context (agent hooks) the captured "active" pane can be wrong, making the restore itself steal focus. Use the pane-scoped window-style option (set-option -p), which writes the same style with no focus side effect, and drop the capture/restore dance. Requires tmux >= 3.0 (already the documented minimum). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Independently reached the same fix on tmux 3.7b before finding this PR, and can confirm both the diagnosis and the resolution. One consequence worth adding to the record: on 3.7b, Reproduction (tmux 3.7b), starting from a zoomed 2-pane window: Verified end to end: a background pane transitioning to |
I've been struggled with this too! Nice to have the fix! |
Problem
apply_pane_style/reset_pane_style(and the inline resets inpane-focus-in.sh/reset_all.sh) tint pane backgrounds withselect-pane -t <pane> -P "bg=…".select-panewith-Pstill makes the target pane the active pane (verified on tmux 3.6a), so any agent state change that styles a non-active pane also moves focus.The capture/restore added in 01b363c mitigates this but can't eliminate it:
tmux display-message -p '#{pane_id}'can resolve a different pane than the one the attached client is on, so the restore itself moves the user's focus.In practice, when working in a window that shares panes with running agents (a common grid layout), focus gets randomly yanked to another pane whenever an agent changes state.
Fix
Write the style through the pane-scoped
window-styleoption instead:This sets the same style (
select-pane -Pis implemented on top of the same pane option) but has no focus side effect, so the capture/restore dance can be dropped entirely. Pane-scoped options need tmux ≥ 3.1, so this PR updates the README minimum from 3.0 to 3.1.Verification
tests/test-pane-style-preserves-focus.shto verify styling and reset preserve the active pane andwindow_zoomed_flagwhile applying the expected background to an inactive pane.bash -n agent-indicator.tmux scripts/*.sh install.sh setup.sh tests/*.sh tests/lib/*.shshellcheck -x -S warning agent-indicator.tmux scripts/*.sh install.sh setup.sh tests/*.sh tests/lib/*.shpython3 -m py_compile scripts/agent-limits.py./tests/run-all.sh🤖 Generated with Claude Code