On Mon, 9 Mar 2026 19:38:15 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.

I ran into some issues with this PR. You can reproduce using the manual 
PopupControlTest or any app that has a standard (non-system) menu bar. Click on 
"Menu" to show the menu's popup, click on the system menu bar to dismiss it, 
and then click on "Menu" again. The popup won't appear.

I debugged this a bit. To track this sort of dismissal the Menu control relies 
on its popup window going through the auto-hide logic (I think auto-hide sets a 
transient property that Menu monitors to detect when the popup goes away). The 
auto-hide logic is normally triggered by a focus ungrab event. It looks like 
there's a similar case in the glass code already; when the user clicks on a 
window's title bar glass calls _ungrabFocus to ensure auto-hiding popups are 
closed (see sendEvent: in GlassWindow.m).

And do we have a policy on Copilot? In this case I think it got something 
half-right but also got several things wrong. I don't like leaving 
misinformation lying around in a PR but also don't want to spend time 
correcting an AI.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/2102#issuecomment-4047906792

Reply via email to