Skip to content

Commit

Permalink
Trying to fix flaky window decorations tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grokys committed Aug 5, 2024
1 parent d1cdb29 commit ccdfc02
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions samples/IntegrationTestApp/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls;
using IntegrationTestApp.Models;
using IntegrationTestApp.Pages;
Expand All @@ -20,6 +22,7 @@ public MainWindow()

DataContext = viewModel;
AppOverlayPopups.Text = Program.OverlayPopups ? "Overlay Popups" : "Native Popups";
PositionChanged += OnPositionChanged;
}

private MainWindowViewModel? ViewModel => (MainWindowViewModel?)DataContext;
Expand Down Expand Up @@ -53,6 +56,22 @@ private void Pager_SelectionChanged(object? sender, SelectionChangedEventArgs e)
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<Page> CreatePages()
{
return
Expand Down

0 comments on commit ccdfc02

Please sign in to comment.