-
Notifications
You must be signed in to change notification settings - Fork 2k
Fixed Incorrect Window.Y and Window.Height values when closing a maximized window #29253
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
Changes from all commits
db34749
44f9453
e8f8d63
e293f1b
17cc880
cd327ba
776440d
16746e6
5438917
00496fa
e12231f
7eac142
2a29755
e819407
69835f4
c42cd91
9770867
343161c
623fd3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,110 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(mainPage, async (handler) => | |
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task WindowsBoundsWhenMaximized() | ||
| { | ||
| SetupBuilder(); | ||
| var mainPage = new NavigationPage(new ContentPage()); | ||
|
|
||
| await CreateHandlerAndAddToWindow<IWindowHandler>(mainPage, async (handler) => | ||
| { | ||
| var appWindowPlatform = handler.PlatformView.GetAppWindow(); | ||
| Assert.NotNull(appWindowPlatform?.Presenter); | ||
| var presenter = Assert.IsType<OverlappedPresenter>(appWindowPlatform.Presenter); | ||
|
|
||
| // maximize window | ||
| presenter.Maximize(); | ||
| var appWindow = handler.PlatformView.GetWindow(); | ||
|
Dhivya-SF4094 marked this conversation as resolved.
|
||
| Assert.NotNull(appWindow); | ||
|
|
||
| // Compute work-area reference values before polling so the same values | ||
| // are used for both the wait predicate and the final assertions. | ||
| // Compare against the monitor's work area. This correctly handles negative | ||
| // coordinates when the window is on a monitor positioned left of or above | ||
| // the primary display, and catches regressions beyond a simple > 0 check. | ||
| var displayArea = DisplayArea.GetFromWindowId(appWindowPlatform.Id, DisplayAreaFallback.Nearest); | ||
| var workArea = displayArea.WorkArea; | ||
| var density = handler.PlatformView.GetDisplayDensity(); | ||
|
|
||
| // Wait until the MAUI frame reflects the maximized work-area bounds. | ||
| // Waiting only for Height > 0 is insufficient: that condition is already true | ||
| // before Maximize() is called, so on slow machines the assertions below would | ||
| // execute against the pre-maximized frame and become flaky. | ||
| await AssertEventually(() => | ||
| Math.Abs(appWindow.Width - workArea.Width / density) < 2 && | ||
| Math.Abs(appWindow.Height - workArea.Height / density) < 2); | ||
|
|
||
| Assert.True(Math.Abs(appWindow.X - workArea.X / density) < 2, | ||
| $"X should be near work area X ({workArea.X / density:F2}) but was {appWindow.X}"); | ||
| Assert.True(Math.Abs(appWindow.Y - workArea.Y / density) < 2, | ||
| $"Y should be near work area Y ({workArea.Y / density:F2}) but was {appWindow.Y}"); | ||
| Assert.True(Math.Abs(appWindow.Width - workArea.Width / density) < 2, | ||
| $"Width should match work area width ({workArea.Width / density:F2}) but was {appWindow.Width}"); | ||
| Assert.True(Math.Abs(appWindow.Height - workArea.Height / density) < 2, | ||
| $"Height should match work area height ({workArea.Height / density:F2}) but was {appWindow.Height}"); | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task WindowsYAndHeightCorrectWhenClosingMaximizedWindow() | ||
| { | ||
| SetupBuilder(); | ||
| var mainPage = new NavigationPage(new ContentPage()); | ||
|
|
||
| double destroyingY = double.NaN; | ||
| double destroyingHeight = double.NaN; | ||
| double expectedY = double.NaN; | ||
| double expectedHeight = double.NaN; | ||
|
|
||
| await CreateHandlerAndAddToWindow<IWindowHandler>(mainPage, async (handler) => | ||
| { | ||
| var window = handler.VirtualView as Window; | ||
| Assert.NotNull(window); | ||
|
|
||
| var appWindowPlatform = handler.PlatformView.GetAppWindow(); | ||
| Assert.NotNull(appWindowPlatform?.Presenter); | ||
| var presenter = Assert.IsType<OverlappedPresenter>(appWindowPlatform.Presenter); | ||
|
|
||
| // Capture the frame values at destroy time so we can verify them after cleanup | ||
| window.Destroying += (s, e) => | ||
| { | ||
| destroyingY = window.Y; | ||
| destroyingHeight = window.Height; | ||
| }; | ||
|
|
||
| // Capture the expected work-area bounds before waiting for the maximized frame, | ||
| // so the same reference values are used for both the wait predicate and the | ||
| // post-cleanup assertions. | ||
| var displayArea = DisplayArea.GetFromWindowId(appWindowPlatform.Id, DisplayAreaFallback.Nearest); | ||
| var workArea = displayArea.WorkArea; | ||
| var density = handler.PlatformView.GetDisplayDensity(); | ||
| expectedY = workArea.Y / density; | ||
| expectedHeight = workArea.Height / density; | ||
|
|
||
| // Maximize the window and wait until the MAUI frame reflects the maximized bounds. | ||
| // Waiting only for Height > 0 is insufficient: that condition is already true | ||
| // before Maximize() is called, so on slow machines the captured values at | ||
| // Destroying time could come from the pre-maximized frame. | ||
| // Do not assert window.Y == 0: on monitors positioned above the primary display | ||
| // Y is legitimately negative. | ||
| presenter.Maximize(); | ||
| await AssertEventually(() => | ||
| Math.Abs(window.Height - expectedHeight) < 2 && | ||
| Math.Abs(window.Y - expectedY) < 2); | ||
| }); | ||
|
|
||
| // The window is destroyed during CreateHandlerAndAddToWindow cleanup. | ||
| // Assert that the bounds reported at Destroying time match the monitor work area, | ||
| // using the same < 2 tolerance as WindowsBoundsWhenMaximized. This catches | ||
| // regressions where Y or Height is off by ~8 pixels when closing a maximized window. | ||
| Assert.False(double.IsNaN(destroyingHeight), "Window.Destroying event was not raised"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Regression Prevention — |
||
| Assert.True(Math.Abs(destroyingY - expectedY) < 2, | ||
| $"Y should be near work area Y ({expectedY:F2}) when closing a maximized window, but was {destroyingY}"); | ||
| Assert.True(Math.Abs(destroyingHeight - expectedHeight) < 2, | ||
| $"Height should match work area height ({expectedHeight:F2}) when closing a maximized window, but was {destroyingHeight}"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ToggleFullscreenTitleBarWorks() | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.