Repository navigation
Fix terminal duplication from pixel-only resizes - #4765
austinywang wants to merge 13 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds pixel-only resize coalescing to prevent redundant PTY resize forwarding to Ghostty during live window dragging. A new static decision function gates forwarding based on whether the target pixel dimensions map to the same terminal grid. ChangesTerminal Pixel-Resize Coalescing
Sequence Diagram(s)sequenceDiagram
participant User as User (drag)
participant NSWindow as NSWindow
participant GhosttyNSView as GhosttyNSView
participant TerminalSurface as TerminalSurface+Sizing
participant Ghostty as Ghostty (ghostty_surface_set_size)
rect rgba(100, 149, 237, 0.5)
Note over User,Ghostty: During live resize
User->>NSWindow: drag window edge
NSWindow->>GhosttyNSView: layout / bounds change
GhosttyNSView->>TerminalSurface: updateSize(coalescePixelOnlyResize: true)
TerminalSurface->>TerminalSurface: ghostty_surface_size → shouldApplySurfacePixelSizeChange
TerminalSurface-->>GhosttyNSView: return scaleChanged (PTY resize skipped)
end
rect rgba(144, 238, 144, 0.5)
Note over User,Ghostty: After live resize ends
User->>NSWindow: release mouse
NSWindow->>GhosttyNSView: viewDidEndLiveResize()
GhosttyNSView->>TerminalSurface: updateSize(coalescePixelOnlyResize: false)
TerminalSurface->>Ghostty: ghostty_surface_set_size (final dimensions)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (2 errors, 1 warning)
✅ Passed checks (18 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryFixes terminal content duplication during live window resize (#3052) by coalescing pixel-only AppKit layout events that don't change the terminal's column/row grid, preventing redundant
Confidence Score: 5/5Safe to merge; coalescing is tightly gated on the live-resize window, grid changes and scale changes always pass through, and the final pixel flush in viewDidEndLiveResize ensures Ghostty receives correct dimensions once the user releases the window edge. The No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant AppKit
participant GhosttyNSView
participant TerminalSurface
participant Ghostty
Note over AppKit,Ghostty: During live resize (isWindowLiveResizeActive = true)
AppKit->>GhosttyNSView: layout()
GhosttyNSView->>TerminalSurface: updateSize(coalescePixelOnlyResize: true)
TerminalSurface->>Ghostty: ghostty_surface_size() [read current grid]
alt pixel-only change (same columns/rows)
TerminalSurface-->>GhosttyNSView: skip ghostty_surface_set_size, return scaleChanged
else grid change OR scale change
TerminalSurface->>Ghostty: ghostty_surface_set_size(wpx, hpx)
TerminalSurface-->>GhosttyNSView: return true
end
Note over AppKit,Ghostty: Live resize ends (isWindowLiveResizeActive = false)
AppKit->>GhosttyNSView: viewDidEndLiveResize()
GhosttyNSView->>TerminalSurface: updateSize(coalescePixelOnlyResize: false)
TerminalSurface->>Ghostty: ghostty_surface_set_size(final wpx, hpx)
TerminalSurface-->>GhosttyNSView: return true
Reviews (10): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile |
|
Waitting for merge! |
|
Is this going to be merged? this is breaking |
|
Also waiting for merge here |
|
Synced this PR with current |
|
Status update: merge conflicts are resolved and the branch is pushed. All GitHub Actions/check-runs are green, and the two Greptile review threads are resolved; latest Greptile summary says safe to merge. The remaining blocker is Vercel: the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@Packages/CmuxTerminal/Sources/CmuxTerminal/Surface/TerminalSurface`+Sizing.swift:
- Around line 55-76: The shouldApplySurfacePixelSizeChange function divides
total pixel dimensions without accounting for padding (non-grid pixels), which
causes it to incorrectly return false when a resize crosses a real Ghostty grid
boundary but only in the padding area, leading updateSize to skip the
ghostty_surface_set_size call. Modify the function signature to accept
currentWidthPx and currentHeightPx parameters, then calculate the non-grid pixel
remainders (the padding) by subtracting the current grid dimensions multiplied
by cell dimensions from these current pixel dimensions. Use these non-grid
remainders when computing target grid dimensions by subtracting them from the
target pixel dimensions before dividing by cell dimensions. Finally, update the
call site at line 145 where this function is invoked to pass
currentSize.width_px and currentSize.height_px as the new parameters.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 646dabaa-dd43-49a2-aa21-5e974ce0ec12
⛔ Files ignored due to path filters (1)
.github/swift-file-length-budget.tsvis excluded by!**/*.tsv
📒 Files selected for processing (3)
Packages/CmuxTerminal/Sources/CmuxTerminal/Surface/TerminalSurface+Sizing.swiftSources/GhosttyTerminalView.swiftcmuxTests/TerminalAndGhosttyTests.swift
…he-window-duplicates-terminal
…6386) * test: cover terminal pixel-only resize coalescing * fix: coalesce terminal pixel-only resizes * fix: keep pixel coalescing scoped to live resize * fix: expose resize policy without testing shim * fix: refresh Swift file length budget * fix: account for terminal padding during resize coalescing * fix: keep resize coalescing grid checks conservative * fix: move resize policy tests to Swift Testing file * fix: clarify live resize coalescing bypass * fix: coalesce same-grid terminal resize shrinks * fix: handle terminal resize padding remainders * fix: keep terminal resize coalescing conservative --------- Co-authored-by: austinpower1258 <austinwang115@gmail.com> Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Issue
Fixes #3052.
Reproduction / testing
Need help on this PR? Tag
@codesmithwith what you need. Autofix is disabled.Note
Medium Risk
Touches the hot path from AppKit layout to Ghostty PTY/SIGWINCH sizing; wrong coalescing could stale renderer pixels or miss grid resizes, but behavior is gated on live resize with explicit end-of-resize flush and unit tests.
Overview
Fixes terminal duplication during live window resize (#3052) by not treating every AppKit pixel tweak as a PTY/grid resize.
TerminalSurface.updateSizenow takescoalescePixelOnlyResize. When enabled (and scale did not change), it compares target pixels to the current column/row grid via newshouldApplySurfacePixelSizeChangeand skipsghostty_surface_set_sizeif only backing pixels moved within the same grid. Coalescing applies only after a first pixel size was applied; grid changes, non-live layout, and scale updates still forward size changes.GhosttyNSViewturns coalescing on whileisWindowLiveResizeActive, andviewDidEndLiveResizecallsupdateSurfaceSize(forcePixelOnlyResize: true)so renderer pixels flush when live resize ends.TerminalSurfaceResizePolicyTestscover coalesced pixel-only churn, grid changes, non-live updates, and first apply.Reviewed by Cursor Bugbot for commit fdadf51. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes terminal duplication during live window resize by coalescing pixel-only resize churn and flushing once resizing ends. Uses conservative grid detection (accounts for padding/remainders) so same-grid pixel tweaks don’t send PTY resizes; grid, scale, and first-apply changes still go through. Fixes #3052.
viewDidEndLiveResize; live-resize state is tracked viaGhosttyNSView.isWindowLiveResizeActive.TerminalSurface.shouldApplySurfacePixelSizeChangewith conservative grid checks and adds Swift Testing coverage inTerminalSurfaceResizePolicyTests.Written for commit 36efd5c. Summary will update on new commits.
Summary by CodeRabbit
Improvements
Tests