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

Remember last editor window mode, size, position and screen across re… #76076

Closed
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
68 changes: 68 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,16 @@ void EditorNode::_notification(int p_what) {
window->set_theme(theme);
}

// Restore windows settings
window_config.instantiate();
Error err = window_config->load(EditorSettings::get_singleton()->get_window_cached_config());
if (err == OK) {
bool restore_window_state = (bool)EDITOR_DEF("interface/editor/remember_window_size_and_position", false);
if (restore_window_state) {
_load_window_config();
}
}

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 @@ -1113,6 +1123,63 @@ void EditorNode::_sources_changed(bool p_exist) {
}
}

void EditorNode::_load_window_config() {
Window *window = get_window();
if (window) {
String mode = window_config->get_value("window", "mode", "maximized");
bool is_windowed = false;
if (mode == "windowed") {
is_windowed = true;
window->set_mode(Window::MODE_WINDOWED);
} else if (mode == "fullscreen") {
window->set_mode(Window::MODE_FULLSCREEN);
} else if (mode == "exclusive_fullscreen") {
window->set_mode(Window::MODE_EXCLUSIVE_FULLSCREEN);
} else {
window->set_mode(Window::MODE_MAXIMIZED);
}

int screen = (int)window_config->get_value("window", "screen", window->get_current_screen());
window->set_current_screen(screen);

if (is_windowed) {
Point2i window_position = (Point2i)window_config->get_value("window", "position", window->get_position());
window->set_position(window_position);

Size2i window_size = (Size2i)window_config->get_value("window", "window_size", window->get_size());
window->set_size(window_size);
}
}
}

void EditorNode::_save_window_config() {
Window *window = get_window();
if (window) {
window_config->set_value("window", "window_size", window->get_size());
window_config->set_value("window", "screen", window->get_current_screen());

Window::Mode mode = window->get_mode();
switch (mode) {
case Window::MODE_WINDOWED:
window_config->set_value("window", "mode", "windowed");
break;
case Window::MODE_FULLSCREEN:
window_config->set_value("window", "mode", "fullscreen");
break;
case Window::MODE_EXCLUSIVE_FULLSCREEN:
window_config->set_value("window", "mode", "exclusive_fullscreen");
break;
default:
window_config->set_value("window", "mode", "maximized");
break;
}

window_config->set_value("window", "position", window->get_position());

window_config->save(EditorSettings::get_singleton()->get_window_cached_config());
}
}

void EditorNode::_scan_external_changes() {
disk_changed_list->clear();
TreeItem *r = disk_changed_list->create_item();
Expand Down Expand Up @@ -3268,6 +3335,7 @@ void EditorNode::_exit_editor(int p_exit_code) {
exiting = true;
resource_preview->stop(); // Stop early to avoid crashes.
_save_docks();
_save_window_config();

// Dim the editor window while it's quitting to make it clearer that it's busy.
dim_editor(true);
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ class EditorNode : public Node {
EditorAbout *about = nullptr;
AcceptDialogAutoReparent *warning = nullptr;

Ref<ConfigFile> window_config;

int overridden_default_layout = -1;
Ref<ConfigFile> default_layout;
PopupMenu *editor_layouts = nullptr;
Expand Down Expand Up @@ -572,6 +574,9 @@ class EditorNode : public Node {
void _resources_reimported(const Vector<String> &p_resources);
void _sources_changed(bool p_exist);

void _load_window_config();
void _save_window_config();

void _node_renamed();
void _editor_select_next();
void _editor_select_prev();
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,10 @@ String EditorSettings::get_editor_layouts_config() const {
return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
}

String EditorSettings::get_window_cached_config() const {
return EditorPaths::get_singleton()->get_cache_dir().path_join("window.cfg");
}

float EditorSettings::get_auto_display_scale() const {
#if defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
return DisplayServer::get_singleton()->screen_get_max_scale();
Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class EditorSettings : public Resource {

Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
String get_editor_layouts_config() const;
String get_window_cached_config() const;
float get_auto_display_scale() const;

void _add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut);
Expand Down