Skip to content

macOS: resample deferred surface resize events - #4625

Open
yay wants to merge 3 commits into
rust-windowing:masterfrom
yay:codex/macos-current-size-after-scale-change
Open

macOS: resample deferred surface resize events#4625
yay wants to merge 3 commits into
rust-windowing:masterfrom
yay:codex/macos-current-size-after-scale-change

Conversation

@yay

@yay yay commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Issue

Notice 20pt-wide black bars. These can show up on egui app launch, if the app was previously open on a bigger screen, got closed, and is now launching on a smaller screen, where the app window has to size down to fit.

black-bars

Summary

Re-sample an AppKit view's backing size when a deferred SurfaceResized callback is delivered,
rather than emitting the size captured when the callback was queued.

This remains a draft while the fix undergoes a downstream soak.

Root cause

AppKit can synchronously resize a view while Winit is already handling an application event. Winit
cannot re-enter the application handler, so WinitView::surface_resized defers its callback to the
default run-loop mode.

AppKit may then continue a live-resize transition in event-tracking mode. Those newer resize events
can be delivered before the default-mode callback resumes. Because the deferred callback captured
its size eagerly, it could subsequently emit an older size and overwrite the renderer's correct
surface configuration.

In the reproduced failure:

  • A 4096x2254 resize was deferred while the window became visible.
  • AppKit continued resizing the surface to 4056x2214.
  • WGPU correctly configured 4056x2214.
  • The older deferred callback then reconfigured WGPU back to 4096x2254.
  • The AppKit view and Metal layer remained 2028x1107 points at a 2x backing scale, leaving
    20-point black bars at the right and bottom edges.

Repainting or changing appearance did not reconfigure the surface, while a manual window resize
did and immediately removed the bars.

Reproduction

  1. Set an Apple Studio Display to 2560x1440 (Default).
  2. Size the window so it almost fills the desktop and close the application.
  3. Change the display resolution to 2048x1152.
  4. Relaunch the application so AppKit constrains the restored window during its first show.

The failure is timing-sensitive, but this sequence makes it substantially easier to reproduce.

Fix

  • Retain the WinitView in the deferred callback and read surface_size() when that callback is
    actually delivered.
  • Route the resize following ScaleFactorChanged through the same helper, preserving
    SurfaceSizeWriter requests while reporting AppKit's authoritative final backing size.

@yay
yay force-pushed the codex/macos-current-size-after-scale-change branch from 060fe7b to 68fbe78 Compare July 20, 2026 23:49
@yay yay changed the title macOS: report current surface size after scale-factor changes macOS: resample deferred surface resize events Jul 20, 2026
@yay
yay marked this pull request as ready for review July 21, 2026 09:47
@yay
yay requested a review from madsmtm as a code owner July 21, 2026 09:47
@yay

yay commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Any thoughts on this fix? It's only a few lines of code and straightforward in nature, so hopefully should be easy to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant