diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 42d931e1246..095756c1b1e 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1590,6 +1590,10 @@ The [Marshalls] singleton. + + The [NativeMenu] singleton. + [b]Note:[/b] Only implemented on macOS. + The [NavigationMeshGenerator] singleton. diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp index b8563f22251..a808a3b1b51 100644 --- a/scene/gui/menu_bar.cpp +++ b/scene/gui/menu_bar.cpp @@ -288,8 +288,8 @@ void MenuBar::_notification(int p_what) { } break; case NOTIFICATION_TRANSLATION_CHANGED: { NativeMenu *nmenu = NativeMenu::get_singleton(); - RID main_menu = nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID); bool is_global = !global_menu_tag.is_empty(); + RID main_menu = is_global ? nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID) : RID(); for (int i = 0; i < menu_cache.size(); i++) { shape(menu_cache.write[i]); if (is_global && menu_cache[i].global_index >= 0) { @@ -492,8 +492,8 @@ void MenuBar::shape(Menu &p_menu) { void MenuBar::_refresh_menu_names() { NativeMenu *nmenu = NativeMenu::get_singleton(); - RID main_menu = nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID); bool is_global = !global_menu_tag.is_empty(); + RID main_menu = is_global ? nmenu->get_system_menu(NativeMenu::MAIN_MENU_ID) : RID(); Vector popups = _get_popups(); for (int i = 0; i < popups.size(); i++) { diff --git a/servers/display_server_headless.h b/servers/display_server_headless.h index af13f8db21c..7a44645b1e3 100644 --- a/servers/display_server_headless.h +++ b/servers/display_server_headless.h @@ -51,6 +51,8 @@ private: return memnew(DisplayServerHeadless()); } + NativeMenu *native_menu = nullptr; + public: bool has_feature(Feature p_feature) const override { return false; } String get_name() const override { return "headless"; } @@ -132,8 +134,15 @@ public: void set_icon(const Ref &p_icon) override {} - DisplayServerHeadless() {} - ~DisplayServerHeadless() {} + DisplayServerHeadless() { + native_menu = memnew(NativeMenu); + } + ~DisplayServerHeadless() { + if (native_menu) { + memdelete(native_menu); + native_menu = nullptr; + } + } }; #endif // DISPLAY_SERVER_HEADLESS_H