Repository navigation
[osx] Use NSTrackingInVisibleRect for mouse movement tracking - #21996
Merged
Merged
Conversation
|
You can test this PR using the following package version. |
kekekeks
reviewed
Aug 17, 2026
kekekeks
reviewed
Aug 17, 2026
|
You can test this PR using the following package version. |
maxkatz6
reviewed
Aug 17, 2026
Co-authored-by: Max Katz <maxkatz6@outlook.com>
|
You can test this PR using the following package version. |
MrJul
approved these changes
Sep 1, 2026
MrJul
left a comment
Member
There was a problem hiding this comment.
Tested, works as expected: no more annoying random popup menu.
LGTM!
MrJul
pushed a commit
to MrJul/Avalonia
that referenced
this pull request
Sep 2, 2026
…iaUI#21996) * [osx] Use NSTrackingInVisibleRect for tracking mouse movement * nit: comment * Update native/Avalonia.Native/src/OSX/AvnView.mm Co-authored-by: Max Katz <maxkatz6@outlook.com> --------- Co-authored-by: Max Katz <maxkatz6@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I finally got so annoyed with this that I took the time to try to fix it.
When you resize a window on macOS, you sometimes see the traffic-light icons highlight, and the drop-down menu for window positioning appear. This is because we had set up an NSTrackingArea on every
setFrameSize, which caused stale locations to be set for the window's mouse position. That would happen to be located in the top-left corner, which would make macOS think the buttons were being highlighted. Instead of recreating it, we can use NSTrackingInVisibleRect once. AppKit follows that; we get the same events, and it doesn't break the mouse positioning.For tracking enter and exit, we can use the real cursor events with
mouseLocationOutsideOfEventStream.andNSEventTypeMouseMoved.** Copilot stuff below **
This pull request addresses issues with mouse tracking and event handling in the
AvnViewimplementation for macOS. The changes ensure more reliable pointer tracking during and after view resizes, and prevent stale or synthetic mouse events from corrupting the pointer state. The most important changes are grouped below by theme.Mouse Tracking Improvements:
_areais now created with theNSTrackingInVisibleRectoption during initialization, so it automatically follows the visible bounds of the view and does not need to be recreated on every resize. This prevents AppKit from queuing synthetic enter/exit events with stale locations during live-resize, which previously corrupted pointer positions. (AvnView.mm, native/Avalonia.Native/src/OSX/AvnView.mmL81-R91)setFrameSize:method was removed, since the tracking area now automatically adjusts with the view. (AvnView.mm, native/Avalonia.Native/src/OSX/AvnView.mmL129-L147)Mouse Event Handling Fixes:
mouseLocationOutsideOfEventStreaminstead of using the stale event location. This ensures accurate pointer position reporting. (AvnView.mm, native/Avalonia.Native/src/OSX/AvnView.mmL259-R260)mouseMovedevents are forwarded up the responder chain; synthetic enter/exit events are not, preventing the window frame from tracking the mouse at incorrect positions. (AvnView.mm, native/Avalonia.Native/src/OSX/AvnView.mmR394-R397)mouseEntered:, the code now checks if the pointer is actually inside the view before processing the event, ignoring false enter events. (AvnView.mm, native/Avalonia.Native/src/OSX/AvnView.mmR566-R568)