Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back from CenterOwner to CenterScreen when owner window is minimized. #7730

Merged
merged 2 commits into from
Mar 2, 2022
Merged
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
15 changes: 13 additions & 2 deletions src/Avalonia.Controls/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,14 +859,25 @@ private void OnGotInputWhenDisabled()

private void SetWindowStartupLocation(IWindowBaseImpl? owner = null)
{
var startupLocation = WindowStartupLocation;

if (startupLocation == WindowStartupLocation.CenterOwner &&
Owner is Window ownerWindow &&
ownerWindow.WindowState == WindowState.Minimized)
{
// If startup location is CenterOwner, but owner is minimized then fall back
// to CenterScreen. This behavior is consistent with WPF.
startupLocation = WindowStartupLocation.CenterScreen;
}

var scaling = owner?.DesktopScaling ?? PlatformImpl?.DesktopScaling ?? 1;

// TODO: We really need non-client size here.
var rect = new PixelRect(
PixelPoint.Origin,
PixelSize.FromSize(ClientSize, scaling));

if (WindowStartupLocation == WindowStartupLocation.CenterScreen)
if (startupLocation == WindowStartupLocation.CenterScreen)
{
var screen = Screens.ScreenFromPoint(owner?.Position ?? Position);

Expand All @@ -875,7 +886,7 @@ private void SetWindowStartupLocation(IWindowBaseImpl? owner = null)
Position = screen.WorkingArea.CenterRect(rect).Position;
}
}
else if (WindowStartupLocation == WindowStartupLocation.CenterOwner)
else if (startupLocation == WindowStartupLocation.CenterOwner)
{
if (owner != null)
{
Expand Down