terminal/tmux: resize existing panes on layout changes#12146
terminal/tmux: resize existing panes on layout changes#12146h3nock wants to merge 1 commit intoghostty-org:mainfrom
Conversation
|
|
||
| // No more errors after this point. We're about to replace all | ||
| // our owned state with our temporary state, and our errdefers | ||
| // above will double-free if there is an error. |
There was a problem hiding this comment.
Was this caveat addressed? It doesn't look like it to me. The error handling looks unsafe...
There was a problem hiding this comment.
i think double free is fine, no? cause after self.panes = panes, i immediately set panes = .empty so the top-level errdefer cleanup in syncLayouts iterates an empty map
on the atomic commit point, i removed errdefer comptime unreachable because adding terminal.resize made the post-handoff path fallible. and currently if resize fails, the error propagates and nextCommand moves the viewer to defunct. not happy with that path, open to a better error handling here.
also tried moving the resize block before the errdefer comptime unreachable line but changed my mind for two reasons 1) reused panes are shallow-copied, so pre-handoff resize still mutates the same terminal objects and can still leave partial state on failure. no way to recover that in place. 2) we'd be mutating terminal state while old (self.panes) and new (panes) maps still coexist, instead of mutating through a single authoritative map after handoff. so i went with the current version to keep mutation on a single authoritative map
happy to revisit if you'd prefer a different shape
What
Resize existing panes when a
layout_changeupdates pane geometry.Why
Today,
layout_changeupdates the window layout tree and handles pane add/remove, but existing panes with the same pane ID are copied forward without reconciling their terminalcols/rowsagainst the new layout width/height.That can leave local pane terminal geometry stale after a split/resize operation.
This change keeps pane terminal geometry aligned with authoritative tmux layout geometry for reused pane IDs.
Changes
PendingPaneResizelist in the tmux viewerinitLayout, if a pane ID already exists:cols/rowswith layoutwidth/heightsyncLayouts:panesvariable after ownership moves toself.panes(panes = .empty)std.math.cast(...)and returnerror.InvalidLayoutSizewhen layout dimensions are out of rangetest "layout change"to verify pane sizes after split:0is83x222is83x21AI disclosure: Claude Code Opus 4.6 and Codex 5.4 xhigh were used for research, understanding and helping me write Zig.