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

Move global_menu_* methods to a separate NativeMenu class. #87452

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
100 changes: 50 additions & 50 deletions doc/classes/DisplayServer.xml

Large diffs are not rendered by default.

685 changes: 685 additions & 0 deletions doc/classes/NativeMenu.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/classes/PopupMenu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@
<member name="submenu_popup_delay" type="float" setter="set_submenu_popup_delay" getter="get_submenu_popup_delay" default="0.3">
Sets the delay time in seconds for the submenu item to popup on mouse hovering. If the popup menu is added as a child of another (acting as a submenu), it will inherit the delay time of the parent menu item.
</member>
<member name="system_menu_root" type="String" setter="set_system_menu_root" getter="get_system_menu_root" default="&quot;&quot;">
If set to one of the values returned by [method DisplayServer.global_menu_get_system_menu_roots], this [PopupMenu] is bound to the special system menu. Only one [PopupMenu] can be bound to each special menu at a time.
<member name="system_menu_id" type="int" setter="set_system_menu" getter="get_system_menu" enum="NativeMenu.SystemMenus" default="0">
If set to one of the values of [enum NativeMenu.SystemMenus], this [PopupMenu] is bound to the special system menu. Only one [PopupMenu] can be bound to each special menu at a time.
</member>
</members>
<signals>
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6584,7 +6584,7 @@ EditorNode::EditorNode() {
main_screen_vbox->add_theme_constant_override("separation", 0);
scene_root_parent->add_child(main_screen_vbox);

bool global_menu = !bool(EDITOR_GET("interface/editor/use_embedded_menu")) && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU);
bool global_menu = !bool(EDITOR_GET("interface/editor/use_embedded_menu")) && NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU);
bool can_expand = bool(EDITOR_GET("interface/editor/expand_to_title")) && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_EXTEND_TO_TITLE);

if (can_expand) {
Expand Down Expand Up @@ -6715,7 +6715,7 @@ EditorNode::EditorNode() {
#ifdef MACOS_ENABLED
if (global_menu) {
apple_menu = memnew(PopupMenu);
apple_menu->set_system_menu_root("_apple");
apple_menu->set_system_menu(NativeMenu::APPLICATION_MENU_ID);
main_menu->add_child(apple_menu);

apple_menu->add_shortcut(ED_GET_SHORTCUT("editor/editor_settings"), SETTINGS_PREFERENCES);
Expand Down Expand Up @@ -6838,7 +6838,7 @@ EditorNode::EditorNode() {

help_menu = memnew(PopupMenu);
help_menu->set_name(TTR("Help"));
help_menu->set_system_menu_root("_help");
help_menu->set_system_menu(NativeMenu::HELP_MENU_ID);
main_menu->add_child(help_menu);

help_menu->connect("id_pressed", callable_mp(this, &EditorNode::_menu_option));
Expand Down
22 changes: 12 additions & 10 deletions editor/gui/editor_scene_tabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,23 @@ void EditorSceneTabs::update_scene_tabs() {
}
menu_initialized = true;

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU)) {
DisplayServer::get_singleton()->global_menu_clear("_dock");
if (NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
NativeMenu::get_singleton()->clear(dock_rid);
}

scene_tabs->set_block_signals(true);
scene_tabs->set_tab_count(EditorNode::get_editor_data().get_edited_scene_count());
scene_tabs->set_block_signals(false);

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU)) {
if (NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
int global_menu_index = DisplayServer::get_singleton()->global_menu_add_item("_dock", EditorNode::get_editor_data().get_scene_title(i), callable_mp(this, &EditorSceneTabs::_global_menu_scene), Callable(), i);
int global_menu_index = NativeMenu::get_singleton()->add_item(dock_rid, EditorNode::get_editor_data().get_scene_title(i), callable_mp(this, &EditorSceneTabs::_global_menu_scene), Callable(), i);
scene_tabs->set_tab_metadata(i, global_menu_index);
}

DisplayServer::get_singleton()->global_menu_add_separator("_dock");
DisplayServer::get_singleton()->global_menu_add_item("_dock", TTR("New Window"), callable_mp(this, &EditorSceneTabs::_global_menu_new_window));
NativeMenu::get_singleton()->add_separator(dock_rid);
NativeMenu::get_singleton()->add_item(dock_rid, TTR("New Window"), callable_mp(this, &EditorSceneTabs::_global_menu_new_window));
}

_update_tab_titles();
Expand Down Expand Up @@ -247,10 +248,11 @@ void EditorSceneTabs::_update_tab_titles() {
bool unsaved = EditorUndoRedoManager::get_singleton()->is_history_unsaved(EditorNode::get_editor_data().get_scene_history_id(i));
scene_tabs->set_tab_title(i, disambiguated_scene_names[i] + (unsaved ? "(*)" : ""));

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU)) {
if (NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
int global_menu_index = scene_tabs->get_tab_metadata(i);
DisplayServer::get_singleton()->global_menu_set_item_text("_dock", global_menu_index, EditorNode::get_editor_data().get_scene_title(i) + (unsaved ? "(*)" : ""));
DisplayServer::get_singleton()->global_menu_set_item_tag("_dock", global_menu_index, i);
NativeMenu::get_singleton()->set_item_text(dock_rid, global_menu_index, EditorNode::get_editor_data().get_scene_title(i) + (unsaved ? "(*)" : ""));
NativeMenu::get_singleton()->set_item_tag(dock_rid, global_menu_index, i);
}

if (show_rb && EditorNode::get_editor_data().get_scene_root_script(i).is_valid()) {
Expand Down
13 changes: 7 additions & 6 deletions editor/project_manager/project_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,11 @@ void ProjectList::set_order_option(int p_option) {
// Global menu integration.

void ProjectList::update_dock_menu() {
if (!DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU)) {
if (!NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU)) {
return;
}
DisplayServer::get_singleton()->global_menu_clear("_dock");
RID dock_rid = NativeMenu::get_singleton()->get_system_menu(NativeMenu::DOCK_MENU_ID);
NativeMenu::get_singleton()->clear(dock_rid);

int favs_added = 0;
int total_added = 0;
Expand All @@ -1025,18 +1026,18 @@ void ProjectList::update_dock_menu() {
favs_added++;
} else {
if (favs_added != 0) {
DisplayServer::get_singleton()->global_menu_add_separator("_dock");
NativeMenu::get_singleton()->add_separator(dock_rid);
}
favs_added = 0;
}
DisplayServer::get_singleton()->global_menu_add_item("_dock", _projects[i].project_name + " ( " + _projects[i].path + " )", callable_mp(this, &ProjectList::_global_menu_open_project), Callable(), i);
NativeMenu::get_singleton()->add_item(dock_rid, _projects[i].project_name + " ( " + _projects[i].path + " )", callable_mp(this, &ProjectList::_global_menu_open_project), Callable(), i);
total_added++;
}
}
if (total_added != 0) {
DisplayServer::get_singleton()->global_menu_add_separator("_dock");
NativeMenu::get_singleton()->add_separator(dock_rid);
}
DisplayServer::get_singleton()->global_menu_add_item("_dock", TTR("New Window"), callable_mp(this, &ProjectList::_global_menu_new_window));
NativeMenu::get_singleton()->add_item(dock_rid, TTR("New Window"), callable_mp(this, &ProjectList::_global_menu_new_window));
}

void ProjectList::_global_menu_new_window(const Variant &p_tag) {
Expand Down
13 changes: 12 additions & 1 deletion platform/android/display_server_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ DisplayServerAndroid *DisplayServerAndroid::get_singleton() {

bool DisplayServerAndroid::has_feature(Feature p_feature) const {
switch (p_feature) {
#ifndef DISABLE_DEPRECATED
case FEATURE_GLOBAL_MENU: {
return (native_menu && native_menu->has_feature(NativeMenu::FEATURE_GLOBAL_MENU));
} break;
#endif
case FEATURE_CURSOR_SHAPE:
//case FEATURE_CUSTOM_CURSOR_SHAPE:
//case FEATURE_GLOBAL_MENU:
//case FEATURE_HIDPI:
//case FEATURE_ICON:
//case FEATURE_IME:
Expand Down Expand Up @@ -578,6 +582,8 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis

keep_screen_on = GLOBAL_GET("display/window/energy_saving/keep_screen_on");

native_menu = memnew(NativeMenu);

#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
RasterizerGLES3::make_current(false);
Expand Down Expand Up @@ -641,6 +647,11 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
}

DisplayServerAndroid::~DisplayServerAndroid() {
if (native_menu) {
memdelete(native_menu);
native_menu = nullptr;
}

#if defined(RD_ENABLED)
if (rendering_device) {
memdelete(rendering_device);
Expand Down
1 change: 1 addition & 0 deletions platform/android/display_server_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DisplayServerAndroid : public DisplayServer {
RenderingContextDriver *rendering_context = nullptr;
RenderingDevice *rendering_device = nullptr;
#endif
NativeMenu *native_menu = nullptr;

ObjectID window_attached_instance_id;

Expand Down
1 change: 1 addition & 0 deletions platform/ios/display_server_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DisplayServerIOS : public DisplayServer {
RenderingContextDriver *rendering_context = nullptr;
RenderingDevice *rendering_device = nullptr;
#endif
NativeMenu *native_menu = nullptr;

id tts = nullptr;

Expand Down
12 changes: 11 additions & 1 deletion platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
if (tts_enabled) {
tts = [[TTS_IOS alloc] init];
}
native_menu = memnew(NativeMenu);

#if defined(RD_ENABLED)
rendering_context = nullptr;
Expand Down Expand Up @@ -134,6 +135,11 @@
}

DisplayServerIOS::~DisplayServerIOS() {
if (native_menu) {
memdelete(native_menu);
native_menu = nullptr;
}

#if defined(RD_ENABLED)
if (rendering_device) {
rendering_device->screen_free(MAIN_WINDOW_ID);
Expand Down Expand Up @@ -309,9 +315,13 @@

bool DisplayServerIOS::has_feature(Feature p_feature) const {
switch (p_feature) {
#ifndef DISABLE_DEPRECATED
case FEATURE_GLOBAL_MENU: {
return (native_menu && native_menu->has_feature(NativeMenu::FEATURE_GLOBAL_MENU));
} break;
#endif
// case FEATURE_CURSOR_SHAPE:
// case FEATURE_CUSTOM_CURSOR_SHAPE:
// case FEATURE_GLOBAL_MENU:
// case FEATURE_HIDPI:
// case FEATURE_ICON:
// case FEATURE_IME:
Expand Down
13 changes: 13 additions & 0 deletions platform/linuxbsd/wayland/display_server_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ void DisplayServerWayland::_show_window() {

bool DisplayServerWayland::has_feature(Feature p_feature) const {
switch (p_feature) {
#ifndef DISABLE_DEPRECATED
case FEATURE_GLOBAL_MENU: {
return (native_menu && native_menu->has_feature(NativeMenu::FEATURE_GLOBAL_MENU));
} break;
#endif
case FEATURE_MOUSE:
case FEATURE_CLIPBOARD:
case FEATURE_CURSOR_SHAPE:
Expand Down Expand Up @@ -1231,6 +1236,8 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
// Input.
Input::get_singleton()->set_event_dispatch_function(dispatch_input_events);

native_menu = memnew(NativeMenu);

#ifdef SPEECHD_ENABLED
// Init TTS
tts = memnew(TTS_Linux);
Expand Down Expand Up @@ -1355,6 +1362,12 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win

DisplayServerWayland::~DisplayServerWayland() {
// TODO: Multiwindow support.

if (native_menu) {
memdelete(native_menu);
native_menu = nullptr;
}

if (main_window.visible) {
#ifdef VULKAN_ENABLED
if (rendering_device) {
Expand Down
1 change: 1 addition & 0 deletions platform/linuxbsd/wayland/display_server_wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class DisplayServerWayland : public DisplayServer {
#ifdef SPEECHD_ENABLED
TTS_Linux *tts = nullptr;
#endif
NativeMenu *native_menu = nullptr;

#if DBUS_ENABLED
FreeDesktopPortalDesktop *portal_desktop = nullptr;
Expand Down
12 changes: 12 additions & 0 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ static String get_atom_name(Display *p_disp, Atom p_atom) {

bool DisplayServerX11::has_feature(Feature p_feature) const {
switch (p_feature) {
#ifndef DISABLE_DEPRECATED
case FEATURE_GLOBAL_MENU: {
return (native_menu && native_menu->has_feature(NativeMenu::FEATURE_GLOBAL_MENU));
} break;
#endif
case FEATURE_SUBWINDOWS:
#ifdef TOUCH_ENABLED
case FEATURE_TOUCHSCREEN:
Expand Down Expand Up @@ -5765,6 +5770,8 @@ static ::XIMStyle _get_best_xim_style(const ::XIMStyle &p_style_a, const ::XIMSt
DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) {
KeyMappingX11::initialize();

native_menu = memnew(NativeMenu);

#ifdef SOWRAP_ENABLED
#ifdef DEBUG_ENABLED
int dylibloader_verbose = 1;
Expand Down Expand Up @@ -6357,6 +6364,11 @@ DisplayServerX11::~DisplayServerX11() {
events_thread_done.set();
events_thread.wait_to_finish();

if (native_menu) {
memdelete(native_menu);
native_menu = nullptr;
}

//destroy all windows
for (KeyValue<WindowID, WindowData> &E : windows) {
#if defined(RD_ENABLED)
Expand Down
1 change: 1 addition & 0 deletions platform/linuxbsd/x11/display_server_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class DisplayServerX11 : public DisplayServer {
#ifdef SPEECHD_ENABLED
TTS_Linux *tts = nullptr;
#endif
NativeMenu *native_menu = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this? Can't we just add the variable and check later, if we ever add proper native menu support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some dummy instance should exist, since it can be accessed in any platform. Also, even if we won't have global menu support we might implement native popup menu at some point (can be useful for the tray indicator menus, and I think the only way tray indicators can be done on X11).


#if defined(DBUS_ENABLED)
FreeDesktopPortalDesktop *portal_desktop = nullptr;
Expand Down
1 change: 1 addition & 0 deletions platform/macos/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ files = [
"godot_menu_delegate.mm",
"godot_menu_item.mm",
"godot_open_save_delegate.mm",
"native_menu_macos.mm",
"dir_access_macos.mm",
"tts_macos.mm",
"joypad_macos.mm",
Expand Down
Loading
Loading