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 30, 2024
1 parent fd7239c commit f624e6a
Show file tree
Hide file tree
Showing 21 changed files with 360 additions and 82 deletions.
1 change: 1 addition & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("display/window/size/transparent", false);
GLOBAL_DEF("display/window/size/extend_to_title", false);
GLOBAL_DEF("display/window/size/no_focus", false);
GLOBAL_DEF("display/window/size/no_title_bar", false);

GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
Expand Down
9 changes: 8 additions & 1 deletion doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,9 @@
<constant name="FEATURE_NATIVE_DIALOG_FILE" value="25" enum="Feature">
Display server supports spawning dialogs for selecting files or directories using the operating system's native look-and-feel. See [method file_dialog_show] and [method file_dialog_with_options_show]. [b]Windows, macOS, Linux (X11/Wayland)[/b]
</constant>
<constant name="FEATURE_NO_TITLE_BAR" value="26" enum="Feature">
Display server supports resizable window without title bar.
</constant>
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
Makes the mouse cursor visible if it is hidden.
</constant>
Expand Down Expand Up @@ -2092,9 +2095,13 @@
<constant name="WINDOW_FLAG_MOUSE_PASSTHROUGH" value="7" enum="WindowFlags">
All mouse events are passed to the underlying window of the same application.
</constant>
<constant name="WINDOW_FLAG_MAX" value="8" enum="WindowFlags">
<constant name="WINDOW_FLAG_MAX" value="9" enum="WindowFlags">
Max value of the [enum WindowFlags].
</constant>
<constant name="WINDOW_FLAG_NO_TITLE_BAR" value="8" enum="WindowFlags">
Hides the window title bar. The window has a border and can be resizable.
[b]Note:[/b] This flag is implemented only on Windows.
</constant>
<constant name="WINDOW_EVENT_MOUSE_ENTER" value="0" enum="WindowEvent">
Sent when the mouse pointer enters the window.
</constant>
Expand Down
4 changes: 4 additions & 0 deletions doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@
<member name="interface/editor/mouse_extra_buttons_navigate_history" type="bool" setter="" getter="">
If [code]true[/code], the mouse's additional side buttons will be usable to navigate in the script editor's file history. Set this to [code]false[/code] if you're using the side buttons for other purposes (such as a push-to-talk button in a VoIP program).
</member>
<member name="interface/editor/no_title_bar" type="bool" setter="" getter="">
Hides the editor main title bar.
Only available to the Windows platform.
</member>
<member name="interface/editor/project_manager_screen" type="int" setter="" getter="">
The preferred monitor to display the project manager.
</member>
Expand Down
4 changes: 4 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@
<member name="display/window/size/no_focus" type="bool" setter="" getter="" default="false">
Main window can't be focused. No-focus window will ignore all input, except mouse clicks.
</member>
<member name="display/window/size/no_title_bar" type="bool" setter="" getter="" default="false">
Hides the window title bar. The window has a border and can be resizable.
[b]Note:[/b] Only available to the Windows platform.
</member>
<member name="display/window/size/resizable" type="bool" setter="" getter="" default="true">
If [code]true[/code], allows the window to be resizable by default.
[b]Note:[/b] This property is only read when the project starts. To change whether the window is resizable at runtime, set [member Window.unresizable] instead on the root Window, which can be retrieved using [code]get_viewport().get_window()[/code]. [member Window.unresizable] takes the opposite value of this setting.
Expand Down
6 changes: 5 additions & 1 deletion doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@
[b]Note:[/b] On Windows, the portion of a window that lies outside the region is not drawn, while on Linux (X11) and macOS it is.
[b]Note:[/b] This property is implemented on Linux (X11), macOS and Windows.
</member>
<member name="no_title" type="bool" setter="set_flag" getter="get_flag" default="false">
</member>
<member name="popup_window" type="bool" setter="set_flag" getter="get_flag" default="false">
If [code]true[/code], the [Window] will be considered a popup. Popups are sub-windows that don't show as separate windows in system's window manager's window list and will send close request when anything is clicked outside of them (unless [member exclusive] is enabled).
</member>
Expand Down Expand Up @@ -842,9 +844,11 @@
All mouse events are passed to the underlying window of the same application.
[b]Note:[/b] This flag has no effect in embedded windows.
</constant>
<constant name="FLAG_MAX" value="8" enum="Flags">
<constant name="FLAG_MAX" value="9" enum="Flags">
Max value of the [enum Flags].
</constant>
<constant name="FLAG_NO_TITLE_BAR" value="8" enum="Flags">
</constant>
<constant name="CONTENT_SCALE_MODE_DISABLED" value="0" enum="ContentScaleMode">
The content will not be scaled to match the [Window]'s size.
</constant>
Expand Down
145 changes: 85 additions & 60 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,29 @@ 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 no_title_bar = bool(EDITOR_GET("interface/editor/no_title_bar")) && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NO_TITLE_BAR);
bool can_expand = !no_title_bar && bool(EDITOR_GET("interface/editor/expand_to_title")) && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_EXTEND_TO_TITLE);

DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_NO_TITLE_BAR, no_title_bar, DisplayServer::MAIN_WINDOW_ID);
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE, can_expand, DisplayServer::MAIN_WINDOW_ID);
title_bar->set_can_move_window(no_title_bar || can_expand);
left_menu_spacer->set_visible(can_expand);
right_menu_spacer->set_visible(can_expand);
project_title->set_visible(no_title_bar || (can_expand && global_menu));
window_buttons->set_visible(no_title_bar);
}

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

Expand Down Expand Up @@ -1253,19 +1272,18 @@ void EditorNode::_viewport_resized() {
}

void EditorNode::_titlebar_resized() {
if (!left_menu_spacer->is_visible()) {
// Not in expand to title mode.
return;
}
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));
}

int w = (gui_base->is_layout_rtl()) ? margin.y : margin.x;
left_menu_spacer->set_custom_minimum_size(Size2(w, 0));
right_menu_spacer->set_custom_minimum_size(Size2(w, 0));

title_bar->set_custom_minimum_size(Size2(0, margin.z - title_bar->get_global_position().y));
}

void EditorNode::_update_undo_redo_allowed() {
Expand Down Expand Up @@ -2022,6 +2040,10 @@ void EditorNode::try_autosave() {
editor_data.save_editor_external_data();
}

void EditorNode::exit() {
_menu_option_confirm(FILE_QUIT, false);
}

void EditorNode::restart_editor() {
exiting = true;

Expand Down Expand Up @@ -5380,6 +5402,13 @@ void EditorNode::_save_window_settings_to_config(Ref<ConfigFile> p_layout, const
break;
}

// Saving the no title bar 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_NO_TITLE_BAR)) {
p_layout->set_value(p_section, "no_title_bar", true);
}

p_layout->set_value(p_section, "position", w->get_position());
}
}
Expand Down Expand Up @@ -6737,6 +6766,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 +7160,21 @@ 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);
// Spacer to center 2D / 3D / Script buttons.
HBoxContainer *title_left_section = memnew(HBoxContainer);
title_left_section->set_mouse_filter(Control::MOUSE_FILTER_PASS);
title_left_section->set_h_size_flags(Control::SIZE_EXPAND_FILL);
title_bar->add_child(title_left_section);

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);

// 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_left_section->add_child(left_menu_spacer);

main_menu = memnew(MenuBar);
title_bar->add_child(main_menu);
title_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,23 +7337,15 @@ 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_left_section->add_child(project_title);

main_editor_button_hb = memnew(HBoxContainer);
title_bar->add_child(main_editor_button_hb);
Expand Down Expand Up @@ -7413,18 +7438,19 @@ 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);
HBoxContainer *title_right_section = memnew(HBoxContainer);
title_right_section->set_mouse_filter(Control::MOUSE_FILTER_PASS);
title_right_section->set_h_size_flags(Control::SIZE_EXPAND_FILL);
title_right_section->set_alignment(BoxContainer::AlignmentMode::ALIGNMENT_END);
title_bar->add_child(title_right_section);

project_run_bar = memnew(EditorRunBar);
title_bar->add_child(project_run_bar);
title_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_right_section->add_child(right_menu_hb);

renderer = memnew(OptionButton);
renderer->set_visible(true);
Expand All @@ -7436,12 +7462,13 @@ EditorNode::EditorNode() {

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);
}
window_buttons = memnew(EditorWindowButtons);
title_right_section->add_child(window_buttons);

// 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_right_section->add_child(right_menu_spacer);

String current_renderer_ps = GLOBAL_GET("rendering/renderer/rendering_method");
current_renderer_ps = current_renderer_ps.to_lower();
Expand Down Expand Up @@ -7908,16 +7935,14 @@ EditorNode::EditorNode() {
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);
}
int window_buttons_size = (window_buttons ? window_buttons->get_minimum_size().x : 0);
int left_side_size = main_menu->get_minimum_size().x;
int right_side_size = project_run_bar->get_minimum_size().x + right_menu_hb->get_minimum_size().x + window_buttons_size;
int max_sides_size = MAX(left_side_size, right_side_size);
title_left_section->set_custom_minimum_size(Size2(max_sides_size, 0));
title_right_section->set_custom_minimum_size(Size2(max_sides_size, 0));

_update_editor_window();

String exec = OS::get_singleton()->get_executable_path();
// Save editor executable path for third-party tools.
Expand Down
7 changes: 7 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class EditorSettingsDialog;
class EditorTitleBar;
class EditorToaster;
class EditorUndoRedoManager;
class EditorWindowButtons;
class ExportTemplateManager;
class FBXImporterManager;
class FileSystemDock;
Expand Down Expand Up @@ -338,6 +339,8 @@ 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;
Expand All @@ -347,6 +350,7 @@ class EditorNode : public Node {
Control *left_menu_spacer = nullptr;
Control *right_menu_spacer = nullptr;
EditorTitleBar *title_bar = nullptr;
EditorWindowButtons *window_buttons = nullptr;
EditorRunBar *project_run_bar = nullptr;
VBoxContainer *main_screen_vbox = nullptr;
MenuBar *main_menu = nullptr;
Expand Down Expand Up @@ -577,6 +581,8 @@ 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();
Expand Down Expand Up @@ -944,6 +950,7 @@ class EditorNode : public Node {
void save_scene_list(const HashSet<String> &p_scene_paths);
void save_before_run();
void try_autosave();
void exit();
void restart_editor();
void unload_editor_addons();

Expand Down
3 changes: 2 additions & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ 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/no_title_bar", false, "", PROPERTY_USAGE_DEFAULT)
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 f624e6a

Please sign in to comment.