-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows]Fixed the PointerGestureRecognizer behaves incorrectly when multiple windows are open. #30537
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
Conversation
|
Hey there @@Ahamed-Ali! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that pointer events are only processed for the currently active window on Windows, preventing background or minimized windows from interfering with live interactions.
- Adds a relevance check (
IsPointerEventRelevantToCurrentElement) before dispatching pointer gestures. - Early-returns from
HandlePgrPointerEventwhen events originate from a different or inactive window. - Encapsulates window-root comparison logic in a private helper with exception safety.
| catch | ||
| { |
Copilot
AI
Jul 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Catching all exceptions silently may mask underlying issues. Consider catching specific exception types and at least logging unexpected errors for diagnostics.
| catch | |
| { | |
| catch (Exception ex) | |
| { | |
| // Log the exception for diagnostics | |
| _logger?.LogError(ex, "An error occurred while validating pointer event relevance."); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ahamed-Ali why are we catching all exceptions here instead of logging or throwing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now logged the exception. @PureWeen
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Show resolved
Hide resolved
|
|
||
| bool IsPointerEventRelevantToCurrentElement(PointerRoutedEventArgs e) | ||
| { | ||
| if (_container is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, can do an early validation of critical dependencies, can include line 690.
if (_container?.XamlRoot is null || e?.OriginalSource is null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have optimized the fix as suggested @jsuarezruiz
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/backport to release/9.0.1xx-sr9 |
|
Started backporting to release/9.0.1xx-sr9: https://github.com/dotnet/maui/actions/runs/16334943485 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we include a device test here https://raw.githubusercontent.com/dotnet/maui/refs/heads/main/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs?
I tried adding a device test, but couldn't reproduce the issue without the fix. When using the Below is the code used in the device test to simulate the issue scenario. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
…re with the active window
Thanks for the investigation. The issue is present in the WinUI sample when using the latest |
|
Is it possible to add a UI test? This looks like it is a "simeple thing to repo" and is "consistent" so a UI test should be ok if we wiggle the mouse or something? I saw this one microsoft/microsoft-ui-xaml#10357 seem to trigger the weird on a click. |
|
/backport to release/9.0.1xx-sr9 |
|
Started backporting to release/9.0.1xx-sr9: https://github.com/dotnet/maui/actions/runs/16890516893 |
…multiple windows are open. (dotnet#30537) * Fixed the PointerGestureRecognizer events from another window interfere with the active window * Optimize the fix * Logging the error * missed paramter * - add some code to debounce when there are multi window scenarios --------- Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
…multiple windows are open. (#30537) * Fixed the PointerGestureRecognizer events from another window interfere with the active window * Optimize the fix * Logging the error * missed paramter * - add some code to debounce when there are multi window scenarios --------- Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root Cause of the issue
Description of Change
This ensures:
Minimized or background windows do not interfere with active window interactions.
Pointer events are scoped and filtered based on the correct visual root or window handle.
Issues Fixed
Fixes #30536
Fixes #27430
Tested the behaviour in the following platforms
Screenshot
WithFlickerofPointerGestures.mp4
WithFixOfPointerGestures.mp4