Skip to content

fix(tmux): pre-size destination window before switch-client - #58

Open
vimeh wants to merge 1 commit into
Ataraxy-Labs:mainfrom
vimeh:fix/presize-switch-window
Open

fix(tmux): pre-size destination window before switch-client#58
vimeh wants to merge 1 commit into
Ataraxy-Labs:mainfrom
vimeh:fix/presize-switch-window

Conversation

@vimeh

@vimeh vimeh commented Jul 30, 2026

Copy link
Copy Markdown

Problem

With window-size latest, every tmux window keeps the size of the last client that viewed it. When the user's terminal size changes over the day (monitor moves, font zoom), switching into a session whose window was last viewed at a different size makes tmux rescale the whole window at attach time: panes are redistributed proportionally, so the sidebar balloons (observed 32 -> 48/56/103 columns) for a visible frame until the after-resize-pane width-repair hook snaps it back.

The user-visible effect is a double reflow on every switch into a stale-sized window: land on a garbled layout, main-pane TUIs start redrawing at the wrong width, then the sidebar snaps back. Measured live this was ~100-300ms of visual churn on ~20% of switches (95 width-repairs across 486 switches in one day's debug log), plus occasional repair storms when consecutive repairs re-trigger the resize hooks.

Fix

TmuxProvider::switch_session now pre-sizes the destination session's active window off-screen before switch-client:

  1. Read the switching client's current window size and the destination's active window size (2 read-only tmux calls; this is the whole cost when sizes already match).
  2. If they differ: resize-window the destination to the client's size, put the sidebar pane back to @opensessions_width, then switch.
  3. After the switch, set-window-option -u window-size restores automatic size tracking, since resize-window pins the window to window-size manual. At that point the recomputed size equals the one just set, so this is never a visible resize.

Attach becomes a layout no-op; the existing width-repair hooks remain as a backstop.

Testing

  • 3 new unit tests over a scripted command runner: command ordering (presize -> switch -> restore tracking), no-op when sizes match, no-op when the client is already on the target session.
  • cargo test --workspace: unit suites green; tmux E2E 22/23 with the one failure (tmux_sidebar_stays_closed_across_session_and_window_switch_hooks) also failing identically on the unmodified base in this environment (host tmux config leaking into the test lab).
  • Verified live: a 20ms-interval pane-width probe during sidebar-driven switches showed the 32->103->32 balloon before the fix and no non-32 samples after.

With window-size latest, attaching a window last viewed at a different
client size rescales every pane proportionally: the sidebar balloons
(32 -> 48/56/103 observed) for a visible frame until the width-repair
hook snaps it back, a double reflow of ~100-300ms on ~20% of switches.
Pre-size the destination session's active window and its sidebar pane
to the switching client's current window size before switch-client so
the attach is a layout no-op, then restore window-size tracking
(resize-window pins the window to manual).

@inspect-review inspect-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspect review

Triage: 16 entities analyzed | 0 critical, 0 high, 9 medium, 7 low
Verdict: standard_review

Findings (0)


Reviewed by inspect | Entity-level triage found 0 high-risk changes

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