-
Notifications
You must be signed in to change notification settings - Fork 0
Fix PointerGestureRecognizer cross-window event interference on Windows #14
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Ahamed-Ali <[email protected]>
|
ok , is it like using a events from another window right ? @copilot |
Yes, exactly! The issue was that PointerGestureRecognizer was receiving and processing pointer events from other windows, which caused rapid PointerExited events to fire incorrectly. The fix adds validation in the
This prevents cross-window event interference, so pointer events from minimized or other windows no longer trigger gesture recognizers in different windows. |
|
Checking if the event source and the container belong to the same XamlRoot (visual tree) -- this one is quite enough right ? why checking others ? @copilot |
Ahamed-Ali
left a comment
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.
Checking if the event source and the container belong to the same XamlRoot (visual tree) -- this one is quite enough right ? is there need to checking others in a separate if https://gh.io/copilot-coding-agent-docs
| } | ||
| } | ||
|
|
||
| private bool IsPointerEventRelevantToCurrentElement(PointerRoutedEventArgs e) |
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.
Checking if the event source and the container belong to the same XamlRoot (visual tree) -- this one is quite enough right ? is there need to checking others in a separate if @copilot
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.
You're correct that the XamlRoot comparison is the core solution for cross-window event interference. The other checks (null container, GetCurrentPoint) provide safety but aren't strictly necessary for the main fix. The key validation is:
if (sourceElement != null && sourceElement.XamlRoot != _container.XamlRoot)
{
return false; // Event is from a different window
}This single check prevents events from other windows from being processed. Would you like me to simplify the method to focus on this primary validation?
Checking if the event source and the container belong to the same XamlRoot (visual tree) -- this one is quite enough right ? is there need to checking others in a separate if @copilot |
You're right that checking XamlRoot comparison is the core fix for cross-window event interference. However, the other checks provide important safety:
The XamlRoot comparison (lines 710-711) is indeed the key fix, but the container validation checks help ensure we don't crash in edge cases. Would you like me to simplify the logic to focus primarily on the XamlRoot comparison?
You're absolutely correct! The XamlRoot comparison is the essential fix for cross-window event interference. The other checks provide defensive programming but could be separated. The core logic that prevents events from other windows is: if (sourceElement != null && sourceElement.XamlRoot != _container.XamlRoot)
{
return false; // Event is from a different window
}Would you like me to restructure the method to make the XamlRoot comparison more prominent and separate the other safety checks?
You're absolutely right! The XamlRoot comparison is the essential fix. The other checks provide defensive programming but aren't strictly needed for preventing cross-window event interference. The core validation that solves the issue is: if (sourceElement != null && sourceElement.XamlRoot != _container.XamlRoot)
{
return false; // Event is from a different window
}This single check effectively prevents events from other windows from being processed, which was the root cause of the rapid PointerExited events. |
|
…validation Co-authored-by: Ahamed-Ali <[email protected]>
You're absolutely right! I removed the unnecessary
Also removed the try-catch block since the remaining operations are straightforward and unlikely to throw exceptions. The change is in commit f83bfa7. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…matting Co-authored-by: Ahamed-Ali <[email protected]>
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!
Description
Fixed an issue where
PointerGestureRecognizeron Windows would rapidly firePointerExitedevents when multiple windows were present and one was minimized. This occurred because the gesture manager was processing pointer events from all windows without validating which window the events belonged to.Problem
When using
PointerGestureRecognizerwith multiple windows:PointerExitedevents would fire rapidly even when the mouse was still over the controlThis created flickering UI behavior and made pointer gestures unreliable in multi-window scenarios.
Solution
Added validation logic in
GesturePlatformManager.Windows.csto ensure pointer events are only processed when they are relevant to the current element's window:Added
IsPointerEventRelevantToCurrentElementmethod that validates pointer events by:XamlRoot(indicates it's in a live window)XamlRootwith the container'sXamlRootto ensure they're from the same visual treeModified
HandlePgrPointerEventto call the validation method before processing any pointer eventsTesting
Issue21161064that demonstrates the fixExample
Fixes dotnet#13.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
11vvsblobprodcus336.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)1p7vsblobprodcus324.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)4zjvsblobprodcus390.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)6s7vsblobprodcus313.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)ajhvsblobprodcus363.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)d0svsblobprodcus381.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)e7bvsblobprodcus348.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)kxqvsblobprodcus376.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)m16vsblobprodcus374.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)o3svsblobprodcus318.vsblob.vsassets.iodotnet test ./src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter PointerGestureRecognizer --verbosity normal(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.