Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ enum APPEARANCE {
NSPanel modalPanel;

Menu menuBar;
boolean mainMenuRefreshPending;
Menu[] menus, popups;
long lastHandledMenuForEventId;

Expand Down Expand Up @@ -5046,6 +5047,36 @@ void setMenuBar (Menu menu) {
nsItem.setEnabled(enabled);
}
}
refreshMainMenu ();
}

/*
* Bug in Cocoa on macOS 27: menu bar changes (swapping the menu bar, inserting
* items) are not shown on screen until the mouse hovers over the menu bar. Fix:
* re-assert the main menu to force AppKit to resync with the window server;
* NSMenu.update() and re-setting the same menu don't help. The menu is retained
* since the application may hold the only reference to it. Deferred via asyncExec
* since an immediate refresh is sometimes ignored (e.g. while a sheet is closing),
* and to coalesce bursts of menu bar changes into one refresh.
*
* TODO: Re-evaluate on future macOS releases whether this workaround is still needed.
*/
void refreshMainMenu () {
if (OS.VERSION < OS.VERSION (27, 0, 0) || mainMenuRefreshPending) {
return;
}
mainMenuRefreshPending = true;
asyncExec (() -> {
mainMenuRefreshPending = false;
NSMenu menubar = application.mainMenu ();
if (menubar == null) {
return;
}
menubar.retain ();
application.setMainMenu (null);
application.setMainMenu (menubar);
menubar.release ();
});
}

void setModalDialog (Dialog modalDialog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ void createItem (MenuItem item, int index) {
if (menubar != null) {
nsItem.setMenu(null);
menubar.insertItem(nsItem, index + 1);
display.refreshMainMenu ();
}
}
}
Expand Down
Loading