You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Remember editor window mode, screen, size and position on restart
This commit is contained in:
@@ -197,6 +197,7 @@ static bool found_project = false;
|
||||
static bool auto_build_solutions = false;
|
||||
static String debug_server_uri;
|
||||
static bool wait_for_import = false;
|
||||
static bool restore_editor_window_layout = true;
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
static int converter_max_kb_file = 4 * 1024; // 4MB
|
||||
static int converter_max_line_length = 100000;
|
||||
@@ -2593,6 +2594,7 @@ Error Main::setup2(bool p_show_boot_logo) {
|
||||
|
||||
bool prefer_wayland_found = false;
|
||||
bool prefer_wayland = false;
|
||||
bool remember_window_size_and_position_found = false;
|
||||
|
||||
if (editor) {
|
||||
screen_property = "interface/editor/editor_screen";
|
||||
@@ -2608,7 +2610,7 @@ Error Main::setup2(bool p_show_boot_logo) {
|
||||
prefer_wayland_found = true;
|
||||
}
|
||||
|
||||
while (!screen_found || !prefer_wayland_found) {
|
||||
while (!screen_found || !prefer_wayland_found || !remember_window_size_and_position_found) {
|
||||
assign = Variant();
|
||||
next_tag.fields.clear();
|
||||
next_tag.name = String();
|
||||
@@ -2628,6 +2630,11 @@ Error Main::setup2(bool p_show_boot_logo) {
|
||||
prefer_wayland = value;
|
||||
prefer_wayland_found = true;
|
||||
}
|
||||
|
||||
if (!remember_window_size_and_position_found && assign == "interface/editor/remember_window_size_and_position") {
|
||||
restore_editor_window_layout = value;
|
||||
remember_window_size_and_position_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2648,6 +2655,34 @@ Error Main::setup2(bool p_show_boot_logo) {
|
||||
}
|
||||
}
|
||||
|
||||
bool has_command_line_window_override = init_use_custom_pos || init_use_custom_screen || init_windowed;
|
||||
if (editor && !has_command_line_window_override && restore_editor_window_layout) {
|
||||
Ref<ConfigFile> config;
|
||||
config.instantiate();
|
||||
// Load and amend existing config if it exists.
|
||||
Error err = config->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg"));
|
||||
if (err == OK) {
|
||||
init_screen = config->get_value("EditorWindow", "screen", init_screen);
|
||||
String mode = config->get_value("EditorWindow", "mode", "maximized");
|
||||
window_size = config->get_value("EditorWindow", "size", window_size);
|
||||
if (mode == "windowed") {
|
||||
window_mode = DisplayServer::WINDOW_MODE_WINDOWED;
|
||||
init_windowed = true;
|
||||
} else if (mode == "fullscreen") {
|
||||
window_mode = DisplayServer::WINDOW_MODE_FULLSCREEN;
|
||||
init_fullscreen = true;
|
||||
} else {
|
||||
window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
|
||||
init_maximized = true;
|
||||
}
|
||||
|
||||
if (init_windowed) {
|
||||
init_use_custom_pos = true;
|
||||
init_custom_pos = config->get_value("EditorWindow", "position", Vector2i(0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Initialize Early Settings");
|
||||
}
|
||||
#endif
|
||||
@@ -2768,6 +2803,30 @@ Error Main::setup2(bool p_show_boot_logo) {
|
||||
OS::get_singleton()->benchmark_end_measure("Servers", "Display");
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
// If the editor is running in windowed mode, ensure the window rect fits
|
||||
// the screen in case screen count or position has changed.
|
||||
if (editor && init_windowed) {
|
||||
// We still need to check we are actually in windowed mode, because
|
||||
// certain platform might only support one fullscreen window.
|
||||
if (DisplayServer::get_singleton()->window_get_mode() == DisplayServer::WINDOW_MODE_WINDOWED) {
|
||||
Vector2i current_size = DisplayServer::get_singleton()->window_get_size();
|
||||
Vector2i current_pos = DisplayServer::get_singleton()->window_get_position();
|
||||
int screen = DisplayServer::get_singleton()->window_get_current_screen();
|
||||
Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(screen);
|
||||
|
||||
Vector2i adjusted_end = screen_rect.get_end().min(current_pos + current_size);
|
||||
Vector2i adjusted_pos = screen_rect.get_position().max(adjusted_end - current_size);
|
||||
Vector2i adjusted_size = DisplayServer::get_singleton()->window_get_min_size().max(adjusted_end - adjusted_pos);
|
||||
|
||||
if (current_pos != adjusted_end || current_size != adjusted_size) {
|
||||
DisplayServer::get_singleton()->window_set_position(adjusted_pos);
|
||||
DisplayServer::get_singleton()->window_set_size(adjusted_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) {
|
||||
// Print requested V-Sync mode at startup to diagnose the printed FPS not going above the monitor refresh rate.
|
||||
switch (window_vsync_mode) {
|
||||
@@ -3823,6 +3882,8 @@ int Main::start() {
|
||||
if (editor_embed_subwindows) {
|
||||
sml->get_root()->set_embedding_subwindows(true);
|
||||
}
|
||||
restore_editor_window_layout = EditorSettings::get_singleton()->get_setting(
|
||||
"interface/editor/remember_window_size_and_position");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user