From 6b0075ddd18ea14ea8e09967b3172cdac5901b0c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 5 Aug 2024 23:40:08 +0200 Subject: [PATCH] Trying to fix flaky window decorations tests. (#16597) Toggling the window decorations can cause the window to be moved off screen, causing integration test failures. Until this bug is fixed, detect this and move the window to the screen origin. See #11411. --- .../IntegrationTestApp/MainWindow.axaml.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/samples/IntegrationTestApp/MainWindow.axaml.cs b/samples/IntegrationTestApp/MainWindow.axaml.cs index 78975daf76..777b9f5c17 100644 --- a/samples/IntegrationTestApp/MainWindow.axaml.cs +++ b/samples/IntegrationTestApp/MainWindow.axaml.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using Avalonia; using Avalonia.Controls; using IntegrationTestApp.Models; using IntegrationTestApp.Pages; @@ -20,6 +22,7 @@ namespace IntegrationTestApp DataContext = viewModel; AppOverlayPopups.Text = Program.OverlayPopups ? "Overlay Popups" : "Native Popups"; + PositionChanged += OnPositionChanged; } private MainWindowViewModel? ViewModel => (MainWindowViewModel?)DataContext; @@ -53,6 +56,22 @@ namespace IntegrationTestApp PagerContent.Child = page.CreateContent(); } + private void OnPositionChanged(object? sender, PixelPointEventArgs e) + { + // HACK: Toggling the window decorations can cause the window to be moved off screen, + // causing test failures. Until this bug is fixed, detect this and move the window + // to the screen origin. See #11411. + if (Screens.ScreenFromWindow(this) is { } screen) + { + var bounds = new PixelRect( + e.Point, + PixelSize.FromSize(ClientSize, DesktopScaling)); + + if (!screen.WorkingArea.Contains(bounds)) + Position = screen.WorkingArea.Position; + } + } + private static IEnumerable CreatePages() { return