On Wed, 25 Mar 2026 19:19:06 GMT, Jose Pereda <[email protected]> wrote:
>> This PR adds a fix to close the popup windows on macOS when clicking over
>> the system menu bar.
>>
>> According to the macOS standard behaviour for native applications, when a
>> popup window is showing, and the user clicks on the system menu bar, the
>> click event is consumed and the popup is closed. A second click is then
>> required to open the system menu bar.
>>
>> This is done by the popup windows directly, as they are NSMenu objects that
>> enable a modal event tracking loop, capturing all events including those
>> from the system menu bar, in order to dismiss the popup when the click is
>> outside the window.
>>
>> However, JavaFX just implements regular NSWindows, and there is no such
>> event loop. Therefore, this PR adds a notification to the system menu
>> instead. When the menu is about to open, the popup window gets a
>> notification, which is processed to cancel the menu animation, preventing it
>> from showing up, and also closing the popup. And then, with the popup
>> closed, a new click from the user will open the system menus as usual.
>>
>> This applies to all JavaFX menus from the system menu bar, that is: the
>> application menu (the "java" menu when the application is not packaged yet)
>> and other menus created by the application, if any.
>>
>> It doesn't apply to the Apple system menu, which is not handle by JavaFX,
>> though. This causes a difference with native applications, that treat such
>> menu in the same way.
>
> Jose Pereda has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Rework menuWillOpenHandler to apply it only to auto-hide popups
modules/javafx.graphics/src/main/native-glass/mac/GlassMenu.m line 187:
> 185: object:_menu
> 186: userInfo:nil];
> 187:
If the system menu is canceled this code will still send out a
jMenuOpeningMethod call for it. The matching jMenuClosedMethod will never be
sent.
I don't think you need the notification (?). In menuWillOpen: you can just
check to see if there's a grab window. If there's a grab window cancel tracking
on the menu, clear the grab, and return. But I sort of like the notification,
it helps verify that there really is a popup open and visible to the user.
modules/javafx.graphics/src/main/native-glass/mac/GlassWindow+Overrides.m line
327:
> 325: // or hiding the popup.
> 326: // Note that only auto-hide popups have an active focus grab.
> 327: if (![self->nsWindow isVisible] || ![GlassWindow _hasGrab]) {
I'm not sure you need the isVisible check though there's no harm in leaving it
in. As far as I know there should never be an invisible popup; when JavaFX
hides the popup the NSWindow is destroyed, not hidden.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/2102#discussion_r3046409870
PR Review Comment: https://git.openjdk.org/jfx/pull/2102#discussion_r3046427262