Skip to content

Commit 6b0075d

Browse files
grokysmaxkatz6
authored andcommitted
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.
1 parent d6f030e commit 6b0075d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

samples/IntegrationTestApp/MainWindow.axaml.cs

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.Collections.Generic;
3+
using Avalonia;
24
using Avalonia.Controls;
35
using IntegrationTestApp.Models;
46
using IntegrationTestApp.Pages;
@@ -20,6 +22,7 @@ public MainWindow()
2022

2123
DataContext = viewModel;
2224
AppOverlayPopups.Text = Program.OverlayPopups ? "Overlay Popups" : "Native Popups";
25+
PositionChanged += OnPositionChanged;
2326
}
2427

2528
private MainWindowViewModel? ViewModel => (MainWindowViewModel?)DataContext;
@@ -53,6 +56,22 @@ private void Pager_SelectionChanged(object? sender, SelectionChangedEventArgs e)
5356
PagerContent.Child = page.CreateContent();
5457
}
5558

59+
private void OnPositionChanged(object? sender, PixelPointEventArgs e)
60+
{
61+
// HACK: Toggling the window decorations can cause the window to be moved off screen,
62+
// causing test failures. Until this bug is fixed, detect this and move the window
63+
// to the screen origin. See #11411.
64+
if (Screens.ScreenFromWindow(this) is { } screen)
65+
{
66+
var bounds = new PixelRect(
67+
e.Point,
68+
PixelSize.FromSize(ClientSize, DesktopScaling));
69+
70+
if (!screen.WorkingArea.Contains(bounds))
71+
Position = screen.WorkingArea.Position;
72+
}
73+
}
74+
5675
private static IEnumerable<Page> CreatePages()
5776
{
5877
return

0 commit comments

Comments
 (0)