Skip to content

fix: set pane background via window-style to avoid unzoom/focus steal - #11

Closed
hammondr wants to merge 1 commit into
accessd:mainfrom
hammondr:fix/pane-bg-window-style
Closed

hammondr wants to merge 1 commit into
accessd:mainfrom
hammondr:fix/pane-bg-window-style

Conversation

@hammondr

Copy link
Copy Markdown

Problem

When an agent updates its state in a background pane (needs-input or done), the pane-background indicator unzooms the user's current window and moves focus to the triggering pane. Anyone who has zoomed one pane to concentrate on it loses that zoom whenever any other tracked pane changes state, and focus jumps away from where they were working.

Root cause

apply_pane_style and reset_pane_style in scripts/agent-state.sh set the pane background with tmux select-pane -t <pane> -P "bg=...". On tmux 3.x, select-pane -P targeting a non-active pane changes the active pane and clears the window zoomed flag as a side effect, even when the only intent is to set a style. The functions then call select-pane -t <previous-active> to put focus back, which restores the active pane but cannot restore the zoom.

Reproduction on tmux 3.7b, starting from a zoomed 2-pane window:

zoom pane %42 (active)               -> window_zoomed_flag=1  active=%42
select-pane -t %43 -P "bg=colour52"  -> window_zoomed_flag=0  active=%43

The same side effect fires for every state that tints a background pane, so a long-running agent that finishes in a hidden pane yanks the user out of their zoom.

Fix

Set the pane background through the pane-level window-style option instead of select-pane -P:

tmux set-option -p -t <pane> window-style "bg=<color>"   # apply
tmux set-option -pu -t <pane> window-style               # clear

set-option -p writes only the pane option. It leaves the active pane and the zoom flag untouched, so no focus juggling or restore call is needed.

This PR converts every set and clear site to window-style so a tint applied one way is cleared the same way:

  • scripts/agent-state.sh: apply_pane_style and reset_pane_style
  • scripts/pane-focus-in.sh: the two focus-in clear paths
  • scripts/reset_all.sh: the bulk reset loop

Verification

Primitive, on tmux 3.7b, starting from a zoomed window:

zoom pane %47 (active)
set-option -p -t %48 window-style "bg=colour52"
-> window_zoomed_flag=1  active=%47  pane %48 background=colour52
set-option -pu -t %48 window-style
-> window-style cleared

End to end: a background pane transitioning to done while another pane is zoomed keeps the zoom and the active pane, tints the background pane, and clears the tint when that pane is focused.

Compatibility and scope

window-style is a standard pane option in tmux 3.x, and both select-pane -P and set-option -p window-style set the pane background, so the rendered result is unchanged. The Knight Rider animation writes a status-bar frame index and does not color panes, so it is unaffected. The active-pane border, window-title styling, and status indicators use set-window-option and status formats rather than select-pane, so they are unaffected as well.

Setting a pane background with `tmux select-pane -t <pane> -P "bg=..."`
changes the active pane and clears the window zoom flag as a side effect
on tmux 3.x. Tinting a background agent's pane therefore unzooms the
user's current window and steals focus to the triggering pane whenever a
tracked agent changes state.

Set the pane background through the pane-level `window-style` option
instead. `set-option -p window-style` writes only the pane option and
leaves the active pane and zoom untouched, so no focus restore is needed.

Convert every set and clear site: apply_pane_style and reset_pane_style
in agent-state.sh, both focus-in clear paths in pane-focus-in.sh, and the
bulk reset loop in reset_all.sh, so a tint applied through window-style is
also cleared through window-style.
@hammondr
hammondr force-pushed the fix/pane-bg-window-style branch from 15b60ca to fc8a680 Compare July 23, 2026 12:58
@hammondr

Copy link
Copy Markdown
Author

Closing as a duplicate of #6, which predates this by six weeks and makes the same change: pane background set through set-option -p window-style in place of select-pane -P, across agent-state.sh, pane-focus-in.sh, and reset_all.sh. I opened this without checking existing PRs first. Deferring to #6, where I have left an independent confirmation on tmux 3.7b.

@hammondr hammondr closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant