Skip to content
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

Try to fix flaky window decorations tests on Windows. #16597

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't only the position be verified instead of the bounds? This might cause an infinite loop if the window somehow doesn't fit into the working area,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is when the bottom of the window is moved below the taskbar so we need to verify the bounds (the problem is that this causes the taskbar to be clicked instead of the window).

I guess we should also add a check that the window size is smaller than the working area though to prevent such an infinite loop.

Position = screen.WorkingArea.Position;
}
}

private static IEnumerable<Page> CreatePages()
{
return
Expand Down
Loading