Skip to content

Commit

Permalink
Editor without title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilderin committed Aug 31, 2024
1 parent fd7239c commit 7b71dd0
Show file tree
Hide file tree
Showing 22 changed files with 478 additions and 180 deletions.
6 changes: 4 additions & 2 deletions doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@
<param index="0" name="window_id" type="int" default="0" />
<description>
Returns left margins ([code]x[/code]), right margins ([code]y[/code]) and height ([code]z[/code]) of the title that are safe to use (contains no buttons or other elements) when [constant WINDOW_FLAG_EXTEND_TO_TITLE] flag is set.
[b]Note:[/b] On Windows, this always returns (0, 0) since the window buttons are not displayed when [constant WINDOW_FLAG_EXTEND_TO_TITLE] flag is set.
</description>
</method>
<method name="window_get_size" qualifiers="const">
Expand Down Expand Up @@ -1866,7 +1867,7 @@
Display server supports text-to-speech. See [code]tts_*[/code] methods. [b]Windows, macOS, Linux (X11/Wayland), Android, iOS, Web[/b]
</constant>
<constant name="FEATURE_EXTEND_TO_TITLE" value="20" enum="Feature">
Display server supports expanding window content to the title. See [constant WINDOW_FLAG_EXTEND_TO_TITLE]. [b]macOS[/b]
Display server supports expanding window content to the title. See [constant WINDOW_FLAG_EXTEND_TO_TITLE]. [b]macOS and Windows[/b]
</constant>
<constant name="FEATURE_SCREEN_CAPTURE" value="21" enum="Feature">
Display server supports reading screen pixels. See [method screen_get_pixel].
Expand Down Expand Up @@ -2087,7 +2088,8 @@
Window content is expanded to the full size of the window. Unlike borderless window, the frame is left intact and can be used to resize the window, title bar is transparent, but have minimize/maximize/close buttons.
Use [method window_set_window_buttons_offset] to adjust minimize/maximize/close buttons offset.
Use [method window_get_safe_title_margins] to determine area under the title bar that is not covered by decorations.
[b]Note:[/b] This flag is implemented only on macOS.
[b]Note:[/b] This flag is implemented only on macOS and Windows.
[b]Note:[/b] On Windows, the window buttons (minimize, maximize and close) are not displayed.
</constant>
<constant name="WINDOW_FLAG_MOUSE_PASSTHROUGH" value="7" enum="WindowFlags">
All mouse events are passed to the underlying window of the same application.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@
</member>
<member name="interface/editor/expand_to_title" type="bool" setter="" getter="">
Expanding main editor window content to the title, if supported by [DisplayServer]. See [constant DisplayServer.WINDOW_FLAG_EXTEND_TO_TITLE].
Specific to the macOS platform.
[b]Note:[/b] Only supported on macOS and Windows.
</member>
<member name="interface/editor/font_allow_msdf" type="bool" setter="" getter="">
If set to [code]true[/code], MSDF font rendering will be used for the visual shader graph editor. You may need to set this to [code]false[/code] when using a custom main font, as some fonts will look broken due to the use of self-intersecting outlines in their font data. Downloading the font from the font maker's official website as opposed to a service like Google Fonts can help resolve this issue.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@
</member>
<member name="display/window/size/extend_to_title" type="bool" setter="" getter="" default="false">
Main window content is expanded to the full size of the window. Unlike a borderless window, the frame is left intact and can be used to resize the window, and the title bar is transparent, but has minimize/maximize/close buttons.
[b]Note:[/b] This setting is implemented only on macOS.
[b]Note:[/b] This setting is implemented only on macOS and Windows.
</member>
<member name="display/window/size/initial_position" type="Vector2i" setter="" getter="" default="Vector2i(0, 0)">
Main window initial position (in virtual desktop coordinates), this setting is used only if [member display/window/size/initial_position_type] is set to "Absolute" ([code]0[/code]).
Expand Down
5 changes: 3 additions & 2 deletions doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
</member>
<member name="extend_to_title" type="bool" setter="set_flag" getter="get_flag" default="false">
If [code]true[/code], the [Window] contents is expanded to the full size of the window, window title bar is transparent.
[b]Note:[/b] This property is implemented only on macOS.
[b]Note:[/b] This property is implemented only on macOS and Windows.
[b]Note:[/b] This property only works with native windows.
</member>
<member name="force_native" type="bool" setter="set_force_native" getter="get_force_native" default="false">
Expand Down Expand Up @@ -835,8 +835,9 @@
</constant>
<constant name="FLAG_EXTEND_TO_TITLE" value="6" enum="Flags">
Window content is expanded to the full size of the window. Unlike borderless window, the frame is left intact and can be used to resize the window, title bar is transparent, but have minimize/maximize/close buttons. Set with [member extend_to_title].
[b]Note:[/b] This flag is implemented only on macOS.
[b]Note:[/b] This flag is implemented only on macOS and Windows.
[b]Note:[/b] This flag has no effect in embedded windows.
[b]Note:[/b] On Windows, the window buttons (minimize, maximize and close) are not displayed.
</constant>
<constant name="FLAG_MOUSE_PASSTHROUGH" value="7" enum="Flags">
All mouse events are passed to the underlying window of the same application.
Expand Down
122 changes: 41 additions & 81 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#include "editor/gui/editor_scene_tabs.h"
#include "editor/gui/editor_title_bar.h"
#include "editor/gui/editor_toaster.h"
#include "editor/gui/editor_window_buttons.h"
#include "editor/history_dock.h"
#include "editor/import/3d/editor_import_collada.h"
#include "editor/import/3d/resource_importer_obj.h"
Expand Down Expand Up @@ -333,11 +334,26 @@ void EditorNode::_update_title() {
title = vformat("(*) %s", title);
}
DisplayServer::get_singleton()->window_set_title(title + String(" - ") + VERSION_NAME);
if (project_title) {
if (project_title->is_visible()) {
project_title->set_text(title);
}
}

void EditorNode::_editor_settings_changed() {
_update_editor_window();
_save_editor_layout();
}

void EditorNode::_update_editor_window() {
bool can_expand = bool(EDITOR_GET("interface/editor/expand_to_title")) && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_EXTEND_TO_TITLE);

DisplayServer::get_singleton()->process_events();
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE, can_expand, DisplayServer::MAIN_WINDOW_ID);

project_title->set_visible(can_expand);
title_bar->update_title_bar();
}

void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Expand Down Expand Up @@ -673,15 +689,11 @@ void EditorNode::_notification(int p_what) {

Engine::get_singleton()->set_editor_hint(true);

Window *window = get_window();
if (window) {
// Handle macOS fullscreen and extend-to-title changes.
window->connect("titlebar_changed", callable_mp(this, &EditorNode::_titlebar_resized));
}

// Theme has already been created in the constructor, so we can skip that step.
_update_theme(true);

_update_editor_window();

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);
Expand Down Expand Up @@ -751,8 +763,6 @@ void EditorNode::_notification(int p_what) {
ProjectSettings::get_singleton()->save();
}

_titlebar_resized();

// Set up a theme context for the 2D preview viewport using the stored preview theme.
CanvasItemEditor::ThemePreviewMode theme_preview_mode = (CanvasItemEditor::ThemePreviewMode)(int)EditorSettings::get_singleton()->get_project_metadata("2d_editor", "theme_preview", CanvasItemEditor::THEME_PREVIEW_PROJECT);
update_preview_themes(theme_preview_mode);
Expand Down Expand Up @@ -1252,22 +1262,6 @@ void EditorNode::_viewport_resized() {
}
}

void EditorNode::_titlebar_resized() {
DisplayServer::get_singleton()->window_set_window_buttons_offset(Vector2i(title_bar->get_global_position().y + title_bar->get_size().y / 2, title_bar->get_global_position().y + title_bar->get_size().y / 2), DisplayServer::MAIN_WINDOW_ID);
const Vector3i &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));
}
if (title_bar) {
title_bar->set_custom_minimum_size(Size2(0, margin.z - title_bar->get_global_position().y));
}
}

void EditorNode::_update_undo_redo_allowed() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
file_menu->set_item_disabled(file_menu->get_item_index(EDIT_UNDO), !undo_redo->has_undo());
Expand Down Expand Up @@ -5380,6 +5374,13 @@ void EditorNode::_save_window_settings_to_config(Ref<ConfigFile> p_layout, const
break;
}

// Saving the extend to title to set the correct window flag on startup
// otherwise the window size will be corrected to a "normal" window causing
// it to move up.
if (w->get_flag(Window::FLAG_EXTEND_TO_TITLE)) {
p_layout->set_value(p_section, "extend_to_title", true);
}

p_layout->set_value(p_section, "position", w->get_position());
}
}
Expand Down Expand Up @@ -6737,6 +6738,7 @@ EditorNode::EditorNode() {
if (!EditorSettings::get_singleton()) {
EditorSettings::create();
}
EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorNode::_editor_settings_changed));

ED_SHORTCUT("editor/lock_selected_nodes", TTR("Lock Selected Node(s)"), KeyModifierMask::CMD_OR_CTRL | Key::L);
ED_SHORTCUT("editor/unlock_selected_nodes", TTR("Unlock Selected Node(s)"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::L);
Expand Down Expand Up @@ -7130,18 +7132,10 @@ 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")) && 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) {
// Add spacer to avoid other controls under window minimize/maximize/close buttons (left side).
left_menu_spacer = memnew(Control);
left_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
title_bar->add_child(left_menu_spacer);
}
global_menu = !bool(EDITOR_GET("interface/editor/use_embedded_menu")) && NativeMenu::get_singleton()->has_feature(NativeMenu::FEATURE_GLOBAL_MENU);

main_menu = memnew(MenuBar);
title_bar->add_child(main_menu);
title_bar->left_section->add_child(main_menu);
main_menu->set_theme_type_variation("MainMenuBar");
main_menu->set_start_index(0); // Main menu, add to the start of global menu.
main_menu->set_prefer_global_menu(global_menu);
Expand Down Expand Up @@ -7304,26 +7298,18 @@ EditorNode::EditorNode() {
ED_SHORTCUT_OVERRIDE("editor/quit_to_project_list", "macos", KeyModifierMask::META + KeyModifierMask::CTRL + KeyModifierMask::ALT + Key::Q);
project_menu->add_shortcut(ED_GET_SHORTCUT("editor/quit_to_project_list"), RUN_PROJECT_MANAGER, true);

// Spacer to center 2D / 3D / Script buttons.
HBoxContainer *left_spacer = memnew(HBoxContainer);
left_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
left_spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
title_bar->add_child(left_spacer);

if (can_expand && global_menu) {
project_title = memnew(Label);
project_title->add_theme_font_override(SceneStringName(font), theme->get_font(SNAME("bold"), EditorStringName(EditorFonts)));
project_title->add_theme_font_size_override(SceneStringName(font_size), theme->get_font_size(SNAME("bold_size"), EditorStringName(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);
project_title->set_mouse_filter(Control::MOUSE_FILTER_PASS);
left_spacer->add_child(project_title);
}
project_title = memnew(Label);
project_title->add_theme_font_override(SceneStringName(font), theme->get_font(SNAME("bold"), EditorStringName(EditorFonts)));
project_title->add_theme_font_size_override(SceneStringName(font_size), theme->get_font_size(SNAME("bold_size"), EditorStringName(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);
project_title->set_mouse_filter(Control::MOUSE_FILTER_PASS);
title_bar->left_section->add_child(project_title);

main_editor_button_hb = memnew(HBoxContainer);
title_bar->add_child(main_editor_button_hb);
title_bar->center_section->add_child(main_editor_button_hb);

// Options are added and handled by DebuggerEditorPlugin.
debug_menu = memnew(PopupMenu);
Expand Down Expand Up @@ -7412,19 +7398,13 @@ EditorNode::EditorNode() {
}
help_menu->add_icon_shortcut(theme->get_icon(SNAME("Heart"), EditorStringName(EditorIcons)), ED_SHORTCUT_AND_COMMAND("editor/support_development", TTR("Support Godot Development")), HELP_SUPPORT_GODOT_DEVELOPMENT);

// 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);
title_bar->add_child(right_spacer);

project_run_bar = memnew(EditorRunBar);
title_bar->add_child(project_run_bar);
title_bar->right_section->add_child(project_run_bar);
project_run_bar->connect("play_pressed", callable_mp(this, &EditorNode::_project_run_started));
project_run_bar->connect("stop_pressed", callable_mp(this, &EditorNode::_project_run_stopped));

HBoxContainer *right_menu_hb = memnew(HBoxContainer);
title_bar->add_child(right_menu_hb);
title_bar->right_section->add_child(right_menu_hb);

renderer = memnew(OptionButton);
renderer->set_visible(true);
Expand All @@ -7433,16 +7413,8 @@ EditorNode::EditorNode() {
renderer->set_fit_to_longest_item(false);
renderer->set_focus_mode(Control::FOCUS_NONE);
renderer->set_tooltip_text(TTR("Choose a rendering method.\n\nNotes:\n- On mobile platforms, the Mobile rendering method is used if Forward+ is selected here.\n- On the web platform, the Compatibility rendering method is always used."));

right_menu_hb->add_child(renderer);

if (can_expand) {
// Add spacer to avoid other controls under the window minimize/maximize/close buttons (right side).
right_menu_spacer = memnew(Control);
right_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
title_bar->add_child(right_menu_spacer);
}

String current_renderer_ps = GLOBAL_GET("rendering/renderer/rendering_method");
current_renderer_ps = current_renderer_ps.to_lower();
String current_renderer_os = OS::get_singleton()->get_current_rendering_method().to_lower();
Expand Down Expand Up @@ -7907,18 +7879,6 @@ EditorNode::EditorNode() {
add_child(screenshot_timer);
screenshot_timer->set_owner(get_owner());

// Adjust spacers to center 2D / 3D / Script buttons.
int max_w = MAX(project_run_bar->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 - project_run_bar->get_minimum_size().x - right_menu_hb->get_minimum_size().x), 0));

// Extend menu bar to window title.
if (can_expand) {
DisplayServer::get_singleton()->process_events();
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE, true, DisplayServer::MAIN_WINDOW_ID);
title_bar->set_can_move_window(true);
}

String exec = OS::get_singleton()->get_executable_path();
// Save editor executable path for third-party tools.
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "executable_path", exec);
Expand Down
8 changes: 5 additions & 3 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,15 @@ class EditorNode : public Node {
bool exiting = false;
bool dimmed = false;

bool global_menu = false;

DisplayServer::WindowMode prev_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
int old_split_ofs = 0;
VSplitContainer *top_split = nullptr;
Control *vp_base = nullptr;

Label *project_title = nullptr;
Control *left_menu_spacer = nullptr;
Control *right_menu_spacer = nullptr;

EditorTitleBar *title_bar = nullptr;
EditorRunBar *project_run_bar = nullptr;
VBoxContainer *main_screen_vbox = nullptr;
Expand Down Expand Up @@ -577,11 +578,12 @@ class EditorNode : public Node {
void _save_editor_states(const String &p_file, int p_idx = -1);
void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
void _update_title();
void _editor_settings_changed();
void _update_editor_window();
void _version_control_menu_option(int p_idx);
void _close_messages();
void _show_messages();
void _vp_resized();
void _titlebar_resized();
void _viewport_resized();

void _update_undo_redo_allowed();
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {

EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_native_file_dialogs", false, "", PROPERTY_USAGE_DEFAULT)
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT)

EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
Expand Down
Loading

0 comments on commit 7b71dd0

Please sign in to comment.