osx: keep window creation on-screen during display reconfiguration - #21543
Merged
MrJul merged 4 commits intoAug 19, 2026
Merged
Conversation
WindowBaseImpl::CreateNSWindow anchors the new NSWindow's content rect to the primary screen's frame.origin. The primary screen is at Cocoa (0,0) on a healthy Mac, but can be offset (often negative) while the display server is mid-reconfiguration -- e.g. CGMainDisplayID() briefly returns 0 after wake-from-sleep -- or on multi-monitor layouts where the primary is not at the origin. Anchoring keeps the window on a real screen so it is positioned on-screen and its flipped Position lands inside a Screen.Bounds. See AvaloniaUI#18895. Co-authored-by: Cursor <cursoragent@cursor.com>
When locating the screen that sizes a new window, fall back to a default size if AppKit reports no screens -- or none whose bounds contain the last-known position -- during a display reconfiguration. The window is repositioned on the next ScreenChanged event once the display server settles. See AvaloniaUI#18895. Co-authored-by: Cursor <cursoragent@cursor.com>
|
You can test this PR using the following package version. |
MrJul
requested changes
Aug 19, 2026
Member
There was a problem hiding this comment.
The changes look good, but please trim down the overly verbose AI comments as per our AI guidelines.
Edit: I've edited one and removed the other.
|
You can test this PR using the following package version. |
MrJul
enabled auto-merge
August 19, 2026 15:06
|
You can test this PR using the following package version. |
MrJul
added a commit
to MrJul/Avalonia
that referenced
this pull request
Sep 2, 2026
…valoniaUI#21543) * osx: anchor new windows to the primary screen origin WindowBaseImpl::CreateNSWindow anchors the new NSWindow's content rect to the primary screen's frame.origin. The primary screen is at Cocoa (0,0) on a healthy Mac, but can be offset (often negative) while the display server is mid-reconfiguration -- e.g. CGMainDisplayID() briefly returns 0 after wake-from-sleep -- or on multi-monitor layouts where the primary is not at the origin. Anchoring keeps the window on a real screen so it is positioned on-screen and its flipped Position lands inside a Screen.Bounds. See AvaloniaUI#18895. Co-authored-by: Cursor <cursoragent@cursor.com> * osx: keep window construction resilient when no screen contains it When locating the screen that sizes a new window, fall back to a default size if AppKit reports no screens -- or none whose bounds contain the last-known position -- during a display reconfiguration. The window is repositioned on the next ScreenChanged event once the display server settles. See AvaloniaUI#18895. Co-authored-by: Cursor <cursoragent@cursor.com> * Less verbose comments --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
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.
What does the pull request do?
On macOS a newly created
NSWindowis given a content rect anchored at Cocoa(0,0), and the screen used to size it is found with.First(m => m.Bounds.Contains(Position)). Both assume the primary screen sits at the origin and that some screen contains the window's position.During a display reconfiguration that does not hold:
CGMainDisplayID()briefly returns 0 and the primary screen'sframe.origingoes negative.In those cases the window is created off-screen, and
WindowImplBase.InitthrowsSequence contains no matching element, aborting window construction.What is the updated behavior?
WindowBaseImpl::CreateNSWindowanchors the content rect to the primary screen's actualframe.origin, so the window is created on a real screen.WindowImplBase.InitusesFirstOrDefaultand falls back to a default window size when no screen contains the position. The window is repositioned on the nextScreenChangedevent once the display server settles (the same patternX11Windowalready uses).Related issue(s)
Part of #18895. Split out of the render-timer change in #21453 per review.
Notes
macOS-only. No behavioral change on a healthy single-monitor Mac, where the primary screen is at
(0,0)and the position is contained.Breaking changes
None.