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

Fix TopMost handling for Popups on Windows #17841

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

StefanKoell
Copy link
Contributor

What does the pull request do?

This PR fixes how the Popup handles the TopMost property on Windows.

What is the current behavior?

All popups on Windows are created with the WS_EX_TOPMOST style. In most scenarios (with IsLightDismissEnabled = true) this is not a problem because the popup is hidden as soon as another window receives the focus.

If IsLightDismissEnabled is set to false (the popup needs to be closed using a user interaction on the popup), the behavior is not correct. Other windows will not cover that popup:
CleanShot 2024-12-28 at 12 37 07

What is the updated/expected behavior with this PR?

The Popup class has actually a property TopMost which should be used to control the behavior. This PR fixes the Popup implementation on Windows to honor the value of the property:
CleanShot 2024-12-28 at 13 04 22

I also created a Popups page in the Control Catalog which can be used to test the change in this PR.

How was the solution implemented (if it's not obvious)?

I think the (small) changes needed to fix the behavior are self-explanatory. If not, I'm happy to elaborate.

Checklist

Not sure how this can be unit tested. Also no public APIs have been altered.

Breaking changes

The previous behavior didn't honor the TopMost property at all - now it does. Since the property default value is false, this PR changes the default behavior and make all Popups NOT top most anymore. I can't really tell if this breaking change has an impact on built-in popups. The usual flyout/popups/tooltips I tested are working fine as far as I can tell.

@maxkatz6
Copy link
Member

Not sure how this can be unit tested.

We have integration tests for Windows and macOS. But it might be challenging to setup.
Test App: https://github.com/AvaloniaUI/Avalonia/tree/master/samples/IntegrationTestApp
Test Methods: https://github.com/AvaloniaUI/Avalonia/tree/master/tests/Avalonia.IntegrationTests.Appium

@maxkatz6
Copy link
Member

This PR fixes #4630 and probably (?) #4227

@maxkatz6
Copy link
Member

I can't really tell if this breaking change has an impact on built-in popups. The usual flyout/popups/tooltips I tested are working fine as far as I can tell.

We can go safe and merge it into 11.3.0, but not backport into 11.2.x.

@Firedragonweb
Copy link

This fixes a problem we discovered recently (did not raise an issue here yet, since we were unsure if we were using it wrongly). I would be really happy if this could find its way in the 11.2.X versions, though.

Comment on lines 7 to 14
<TextBlock Text="'Light Dismiss' Popup" />
<Button Content="Show Popup" Click="ButtonLightDismiss_OnClick" />

<TextBlock Text="Popup that stays open" />
<Button Content="Show Popup" Click="ButtonPopupStaysOpen_OnClick" />

<TextBlock Text="TopMost popup that stays open" />
<Button Content="Show Popup" Click="ButtonTopMostPopupStaysOpen" />
Copy link
Member

Choose a reason for hiding this comment

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

These testing buttons can be moved to the IntegrationTestApp. I can try to add integration test on top of them later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could use some guidance on this one. Not sure what I should do 😳

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the required integration tests are still blocking this from being merged. @maxkatz6, any pointers on how I can test this particular fix? I've never worked with and to be honest I can't make any sense of the existing tests to find out how I would go about this.

Copy link
Member

Choose a reason for hiding this comment

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

@StefanKoell I just pushed popup integration tests. Based on your popup page. These work on Windows, need yet to check on macOS, but should be fine (if not, better to temporary skip them unless it's a new bug).

Copy link
Member

Choose a reason for hiding this comment

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

@StefanKoell integrational tests are running an actual app (IntegrationTestApp project). So when there is a failing test, you usually can manually run this project and reproduce test steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to add to this: it seems that roughly 1/3 of all the tests are green and the rest fails like shown in the screenshot.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Seems like some test is crashing testing app for you. Maybe you can try to isolate it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxkatz6 tried to isolate and it seems that for the popup tests, the click on the button doesn't open the popup at all. When I run the test app manually and click on the button, the popup opens up. In the test, I can confirm that the button is found and the click is executed but the popup never shows up.

I tested it on 2 different machines (both Windows 11 24H2 on ARM64). Most of the tests are behaving weird on those machines.

I tried WinAppDriver, last stable release and the "release candidate" which offers an ARM64 binary. Unfortunately both behave the same way.

As far as I can tell it is an issue with ARM64 but I can't really confirm that because I don't have access to a x64 machine at the moment.

I'm not sure what else I can do to finish up the PR. Any suggestions? Can someone else help out here?

On a positive side: I know now much more about the integration tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxkatz6 I just pushed another commit which should fix the failed test - at least manually I can't reproduce the issue anymore with the grandchild menu item. The solution I came up with is not elegant, I guess. I'm simply delaying the popup activation which seems to be enough for the menu click handler to get processed. I'm not sure if this can be solved differently. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still not sure what to do with the integration tests. I see also a lot of tests failing in the CI pipeline here. Is this expected?

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054093-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054095-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@StefanKoell
Copy link
Contributor Author

Hi @maxkatz6
I worked with the fix PR for a while and wanted to report back, that everything seems to work as expected.

I do see a difference in behavior though and I was wondering if there's a way to improve it:

  • When I use OverlayPopups = true, it is not a dedicated window or "embedded" into the parent area. In this case, any rendering during resize is applied immediately.
  • When I use the OverlayPopups = false so that the popup "Window' is created, resizing is a bit delayed which looks kind of weird and choppy. I was wondering if there's a way to resize the overlayed window in concert with the parent area to look more like the "embedded" variant.

Other than that, everything works really well. I hope this PR and the ShouldConstrainToRootBounds PR can be merged. If there's anything else from my side to do, let me know.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054198-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054538-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@StefanKoell
Copy link
Contributor Author

@maxkatz6 You are probably swamped with the Accelerate stuff but I just wanted to check back if this is still on track for 11.3? If there's anything I can/need to do, let me know.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054578-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054582-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054642-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054783-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@@ -917,7 +917,7 @@ void PlatformImpl_LostFocus()
while (focused.VisualParent != null)
focused = focused.VisualParent;

if (focused == this)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxkatz6 found another small issue with popups and input elements when the window is deactivated.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054839-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants