From c71fa11e73b76850a923150a864c30017fb5cd84 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 8eac3a5886..ee7c81bf22 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