From 0dab11afa4dca6bba7aba554ec4097de30200f73 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 22 Sep 2022 12:06:11 +0300 Subject: [PATCH] [macOS extend-to-title] Add scene/project name to the editor title, fix incorrect window button position/order when system primary language is RTL. --- doc/classes/DisplayServer.xml | 2 + doc/classes/Window.xml | 5 ++ editor/editor_node.cpp | 70 ++++++++++++++++++------- editor/editor_node.h | 6 ++- platform/macos/display_server_macos.mm | 31 +++++------ platform/macos/godot_button_view.h | 3 +- platform/macos/godot_button_view.mm | 23 +++++--- platform/macos/godot_window.h | 2 + platform/macos/godot_window.mm | 13 +++++ platform/macos/godot_window_delegate.h | 2 + platform/macos/godot_window_delegate.mm | 56 ++++++++++++++++++-- scene/main/window.cpp | 4 ++ servers/display_server.cpp | 1 + servers/display_server.h | 1 + 14 files changed, 171 insertions(+), 48 deletions(-) diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index f93a14b4aca..6d3f3a7362e 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -1548,6 +1548,8 @@ + + No vertical synchronization, which means the engine will display frames as fast as possible (tearing may be visible). diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index 2bae2d95926..c585b54ee18 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -455,6 +455,11 @@ Emitted when the [constant NOTIFICATION_THEME_CHANGED] notification is sent. + + + Emitted when window title bar decorations are changed, e.g., macOS window enter/exit full screen mode, or extend-to-title flag is changed. + + Emitted when [Window] is made visible or disappears. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c8bd9a9c442..673fa3404c9 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -429,7 +429,7 @@ void EditorNode::_version_control_menu_option(int p_idx) { void EditorNode::_update_title() { const String appname = ProjectSettings::get_singleton()->get("application/config/name"); - String title = (appname.is_empty() ? TTR("Unnamed Project") : appname) + String(" - ") + VERSION_NAME; + String title = (appname.is_empty() ? TTR("Unnamed Project") : appname); const String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_scene_file_path() : String(); if (!edited.is_empty()) { // Display the edited scene name before the program name so that it can be seen in the OS task bar. @@ -439,8 +439,10 @@ void EditorNode::_update_title() { // Display the "modified" mark before anything else so that it can always be seen in the OS task bar. title = vformat("(*) %s", title); } - - DisplayServer::get_singleton()->window_set_title(title); + DisplayServer::get_singleton()->window_set_title(title + String(" - ") + VERSION_NAME); + if (project_title) { + project_title->set_text(title); + } } void EditorNode::shortcut_input(const Ref &p_event) { @@ -659,6 +661,12 @@ void EditorNode::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { Engine::get_singleton()->set_editor_hint(true); + Window *window = static_cast(get_tree()->get_root()); + if (window) { + // Handle macOS fullscreen and extend-to-title changes. + window->connect("titlebar_changed", callable_mp(this, &EditorNode::_titlebar_resized)); + } + OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec"))); get_tree()->get_root()->set_as_audio_listener_3d(false); get_tree()->get_root()->set_as_audio_listener_2d(false); @@ -713,6 +721,8 @@ void EditorNode::_notification(int p_what) { ProjectSettings::get_singleton()->save(); } + _titlebar_resized(); + /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ } break; @@ -1170,6 +1180,18 @@ void EditorNode::_reload_project_settings() { void EditorNode::_vp_resized() { } +void EditorNode::_titlebar_resized() { + const Size2 &margin = DisplayServer::get_singleton()->window_get_safe_title_margins(DisplayServer::MAIN_WINDOW_ID); + if (left_menu_spacer) { + int w = (gui_base->is_layout_rtl()) ? margin.y : margin.x; + left_menu_spacer->set_custom_minimum_size(Size2(w, 0)); + } + if (right_menu_spacer) { + int w = (gui_base->is_layout_rtl()) ? margin.x : margin.y; + right_menu_spacer->set_custom_minimum_size(Size2(w, 0)); + } +} + void EditorNode::_version_button_pressed() { DisplayServer::get_singleton()->clipboard_set(version_btn->get_meta(META_TEXT_TO_COPY)); } @@ -3390,7 +3412,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed tb->add_theme_font_size_override("font_size", singleton->gui_base->get_theme_font_size(SNAME("main_button_font_size"), SNAME("EditorFonts"))); singleton->main_editor_buttons.push_back(tb); - singleton->main_editor_button_vb->add_child(tb); + singleton->main_editor_button_hb->add_child(tb); singleton->editor_table.push_back(p_editor); singleton->distraction_free->move_to_front(); @@ -6590,14 +6612,14 @@ EditorNode::EditorNode() { if (can_expand) { // Add spacer to avoid other controls under window minimize/maximize/close buttons (left side). - Control *menu_spacer = memnew(Control); - menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS); - menu_spacer->set_custom_minimum_size(Size2(DisplayServer::get_singleton()->window_get_safe_title_margins(DisplayServer::MAIN_WINDOW_ID).x, 0)); - menu_hb->add_child(menu_spacer); + left_menu_spacer = memnew(Control); + left_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS); + menu_hb->add_child(left_menu_spacer); } main_menu = memnew(MenuBar); menu_hb->add_child(main_menu); + main_menu->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("MenuHover"), SNAME("EditorStyles"))); main_menu->set_flat(true); main_menu->set_start_index(0); // Main menu, add to the start of global menu. @@ -6766,22 +6788,30 @@ EditorNode::EditorNode() { project_menu->add_shortcut(ED_GET_SHORTCUT("editor/quit_to_project_list"), RUN_PROJECT_MANAGER, true); // Spacer to center 2D / 3D / Script buttons. - Control *left_spacer = memnew(Control); + HBoxContainer *left_spacer = memnew(HBoxContainer); left_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS); + left_spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL); menu_hb->add_child(left_spacer); - menu_hb->add_spacer(); + if (can_expand && global_menu) { + project_title = memnew(Label); + project_title->add_theme_font_override("font", gui_base->get_theme_font(SNAME("bold"), SNAME("EditorFonts"))); + project_title->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"))); + project_title->set_focus_mode(Control::FOCUS_NONE); + project_title->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); + project_title->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); + project_title->set_h_size_flags(Control::SIZE_EXPAND_FILL); + left_spacer->add_child(project_title); + } - main_editor_button_vb = memnew(HBoxContainer); - menu_hb->add_child(main_editor_button_vb); + main_editor_button_hb = memnew(HBoxContainer); + menu_hb->add_child(main_editor_button_hb); // Options are added and handled by DebuggerEditorPlugin. debug_menu = memnew(PopupMenu); debug_menu->set_name(TTR("Debug")); main_menu->add_child(debug_menu); - menu_hb->add_spacer(); - settings_menu = memnew(PopupMenu); settings_menu->set_name(TTR("Editor")); main_menu->add_child(settings_menu); @@ -6855,6 +6885,7 @@ EditorNode::EditorNode() { // Spacer to center 2D / 3D / Script buttons. Control *right_spacer = memnew(Control); right_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS); + right_spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL); menu_hb->add_child(right_spacer); launch_pad = memnew(PanelContainer); @@ -6965,10 +6996,9 @@ EditorNode::EditorNode() { if (can_expand) { // Add spacer to avoid other controls under the window minimize/maximize/close buttons (right side). - Control *menu_spacer = memnew(Control); - menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS); - menu_spacer->set_custom_minimum_size(Size2(DisplayServer::get_singleton()->window_get_safe_title_margins(DisplayServer::MAIN_WINDOW_ID).y, 0)); - menu_hb->add_child(menu_spacer); + right_menu_spacer = memnew(Control); + right_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS); + menu_hb->add_child(right_menu_spacer); } String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method"); @@ -7523,9 +7553,9 @@ EditorNode::EditorNode() { screenshot_timer->set_owner(get_owner()); // Adjust spacers to center 2D / 3D / Script buttons. - int max_w = MAX(launch_pad_hb->get_minimum_size().x + right_menu_hb->get_minimum_size().x, main_menu->get_minimum_size().x); + int max_w = MAX(launch_pad->get_minimum_size().x + right_menu_hb->get_minimum_size().x, main_menu->get_minimum_size().x); left_spacer->set_custom_minimum_size(Size2(MAX(0, max_w - main_menu->get_minimum_size().x), 0)); - right_spacer->set_custom_minimum_size(Size2(MAX(0, max_w - launch_pad_hb->get_minimum_size().x - right_menu_hb->get_minimum_size().x), 0)); + right_spacer->set_custom_minimum_size(Size2(MAX(0, max_w - launch_pad->get_minimum_size().x - right_menu_hb->get_minimum_size().x), 0)); // Extend menu bar to window title. if (can_expand) { diff --git a/editor/editor_node.h b/editor/editor_node.h index 14dab113589..fab280bc14c 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -322,6 +322,9 @@ private: HBoxContainer *bottom_hb = nullptr; Control *vp_base = nullptr; + Label *project_title = nullptr; + Control *left_menu_spacer = nullptr; + Control *right_menu_spacer = nullptr; EditorTitleBar *menu_hb = nullptr; VBoxContainer *main_screen_vbox = nullptr; MenuBar *main_menu = nullptr; @@ -397,7 +400,7 @@ private: String current_path; MenuButton *update_spinner = nullptr; - HBoxContainer *main_editor_button_vb = nullptr; + HBoxContainer *main_editor_button_hb = nullptr; Vector