Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeMenu] Add checks to avoid unnecessary warnings. #89224

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
4 changes: 4 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,10 @@
<member name="Marshalls" type="Marshalls" setter="" getter="">
The [Marshalls] singleton.
</member>
<member name="NativeMenu" type="NativeMenu" setter="" getter="">
The [NativeMenu] singleton.
[b]Note:[/b] Only implemented on macOS.
</member>
<member name="NavigationMeshGenerator" type="NavigationMeshGenerator" setter="" getter="">
The [NavigationMeshGenerator] singleton.
</member>
Expand Down
4 changes: 2 additions & 2 deletions scene/gui/menu_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<PopupMenu *> popups = _get_popups();
for (int i = 0; i < popups.size(); i++) {
Expand Down
13 changes: 11 additions & 2 deletions servers/display_server_headless.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DisplayServerHeadless : public DisplayServer {
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"; }
Expand Down Expand Up @@ -132,8 +134,15 @@ class DisplayServerHeadless : public DisplayServer {

void set_icon(const Ref<Image> &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
Loading