Repository navigation
macos: Keep a zoomed window's normal frame from before the zoom - #1434
Merged
Merged
Conversation
AppKit animates zoom:, and the window posts moves and resizes for the frames on the way. The main window's state is read on each of them, and as the window is not zoomed yet, every animated frame was kept as its windowed frame. A zoomed window's placement then carried a frame close to the zoomed one: restoreBounds saved it, and after a relaunch leaving the zoom brought the window back to nearly the zoomed size. Every zoom: asks the window's delegate windowShouldZoom:toFrame: first. The standalone main window's delegate and the delegate of the app's own windows now keep the frame there and hold it until the window is zoomed. A host app's window keeps its own delegate and the old behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On macOS, a zoomed (maximized) window's placement carries the wrong normal bounds: a frame close to the zoomed one instead of the one the window had before the zoom. With
restoreBounds, that is what gets saved, so after quitting while zoomed and launching again, leaving the zoom brings the window back to nearly the zoomed size instead of where the user had it.The cause: AppKit animates
zoom:, and the window postsNSWindowDidResize/NSWindowDidMovefor the frames on the way. The main window's state is read on each of them, and since the window is not zoomed yet,read_windowkept each animated frame as the windowed frame (Watch::windowed). Once the window is zoomed, the last frame of the animation is what remained. The same happens when the runner opens a kept maximized window (it sets the kept frame, then zooms).The fix: every
zoom:(the Window menu, the zoom button, a double click on the title bar,WindowRef.setMode/setPlacement, the runner's launch) asks the window's delegatewindowShouldZoom:toFrame:first. The standalone main window's delegate and the delegate of the app's own windows now answer it withwindow_state::will_zoom, which keeps the frame the window has then as its windowed frame and holds it until a read sees the window zoomed (or in full screen, or minimized). Leaving the zoom is unchanged: the moves on the way are normal-mode reads, and the last one is the frame AppKit restores.A window of a host app that embeds an
AppViewhas the host's delegate, so it keeps the old behavior.How to Test
Manual, on macOS 27.0.1 (one display, 1800×1169), with
examples/tasks-rschanged locally (not in this PR) to open withrestoreBounds:HOMEpointed at an empty directory, the window moved and resized through System Events, zoomed through Window > Zoom, quit withkill, and the kept placement read from the app'sstorage.json(nsh.window:main):Also checked after the fix, in one run: zoom and leave it, then move and resize to 300, 200, 640×480, zoom again (kept: maximized 300, 200, 640×480) and leave it (back to 300, 200, 640×480); full screen in and out through
AXFullScreen(kept: fullScreen with 300, 200, 640×480, then normal at the same frame), as before.No automated test: the behavior needs a real
NSWindow, its zoom animation and the runner's launch on the main thread; the crate's window tests don't drive a standalone app's launch.Checks:
cargo +nightly fmt --allcargo clippy -p nsh-platform-macos -p nsh-macos-host -p nsh-macos-app --all-targets: no warningscargo test -p nsh-platform-macos: 115 unit tests and the window tests passChecklist
cargo test --workspace,cargo +nightly fmt --alland clippy (including the Catalyst and Android runs for platform code). — fmt and the macOS crates' clippy and tests; the change is innsh-platform-macosonly.tests/compat/(cargo xtask compat). — no change to what apps use.examples/gallerydemos on iOS and Android (if the change is visible or platform-specific). — macOS only; run on macOS as above.