Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,21 @@ static void ActivateApplication() {
}

void WindowBaseImpl::CreateNSWindow(bool usePanel) {
// Anchor the content rect to the primary screen's origin. It's usually at (0,0), but can be offset while the
// display server is mid-reconfiguration. This ensures the window is always on a proper screen.
// See https://github.com/AvaloniaUI/Avalonia/issues/18895
NSPoint origin = NSZeroPoint;
NSArray<NSScreen*>* screens = [NSScreen screens];
if (screens.count > 0)
origin = screens.firstObject.frame.origin;

NSRect contentRect = NSRect { origin.x, origin.y, lastSize };

if (usePanel) {
Window = [[AvnPanel alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:NSWindowStyleMaskBorderless];
Window = [[AvnPanel alloc] initWithParent:this contentRect:contentRect styleMask:NSWindowStyleMaskBorderless];
[Window setHidesOnDeactivate:false];
} else {
Window = [[AvnWindow alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:NSWindowStyleMaskBorderless];
Window = [[AvnWindow alloc] initWithParent:this contentRect:contentRect styleMask:NSWindowStyleMaskBorderless];
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/Avalonia.Native/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ internal override void Init(MacOSTopLevelHandle handle)

base.Init(handle);

int defaultWidth = 0, defaultHeight = 0;

var monitor = this.TryGetFeature<IScreenImpl>()!.AllScreens
.OrderBy(x => x.Scaling)
.First(m => m.Bounds.Contains(Position));
.FirstOrDefault(m => m.Bounds.Contains(Position));

if (monitor != null)
{
// Emulate Windows 7+ default window size behavior.
defaultWidth = (int)(monitor.WorkingArea.Width * 0.75d);
defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d);
}

defaultWidth = Math.Max(defaultWidth, 300);
defaultHeight = Math.Max(defaultHeight, 200);

Resize(new Size(monitor.WorkingArea.Width * 0.75d, monitor.WorkingArea.Height * 0.7d), WindowResizeReason.Layout);
Resize(new Size(defaultWidth, defaultHeight), WindowResizeReason.Layout);
}

public void Activate()
Expand Down