NSMenuItem's custom view property returns wrong locationInWindow value on NSResponder's mouseExited method

After popping up a NSMenu a few times, NSResponder's mouseExited event is called even when the cursor is inside the tracking area, returning the main app window's max X value, which makes the mouseEntered/Exited methods unusable for tracking whether or not cursor is currently inside the view's frame.

Steps

  • Create a NSMenuItem with a custom view inside
  • Add a tracking area to the views frame
  • Add a background color that changes on mouseEntered/Exited
  • Open and close NSMenu a few times until the color starts flickering when moving the cursor inside the view's frame
  • If possible, print out NSEvent's locationInWindow on both mouseEntered and Exited and see that the location for exited method is not being reported correctly, while the flickering from the bg color being set is happening.

Expected Result

mouseExited should only be called the cursor leaves the tracking area. locationInWindow values should not exceed the NSPopUpWindow's frame.

Tested on

macOS Sonoma 14.3.1 and 14.4.1; Xcode 15.2;

Feedback ID

https://feedbackassistant.apple.com/feedback/13698735

Post not yet marked as solved Up vote post of LucasFrazao Down vote post of LucasFrazao
270 views