Skip to content

Commit

Permalink
[DisplayServer] Decouple show_window(MAIN_WINDOW_ID) from `DisplayS…
Browse files Browse the repository at this point in the history
…erver` constructor, update project manager size/position after DS init.
  • Loading branch information
bruvzg committed Jan 24, 2025
1 parent b0655dc commit a303e54
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6878,7 +6878,7 @@ EditorNode::EditorNode() {
switch (display_scale) {
case 0:
// Try applying a suitable display scale automatically.
EditorScale::set_scale(EditorSettings::get_singleton()->get_auto_display_scale());
EditorScale::set_scale(EditorSettings::get_auto_display_scale());
break;
case 1:
EditorScale::set_scale(0.75);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ String EditorSettings::get_editor_layouts_config() const {
return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
}

float EditorSettings::get_auto_display_scale() const {
float EditorSettings::get_auto_display_scale() {
#ifdef LINUXBSD_ENABLED
if (DisplayServer::get_singleton()->get_name() == "Wayland") {
float main_window_scale = DisplayServer::get_singleton()->screen_get_scale(DisplayServer::SCREEN_OF_MAIN_WINDOW);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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;
float get_auto_display_scale() const;
static float get_auto_display_scale();

void _add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut);
void add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut);
Expand Down
16 changes: 4 additions & 12 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,15 @@ void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {

// Main layout.

void ProjectManager::_update_size_limits(bool p_custom_res) {
void ProjectManager::_update_size_limits() {
const Size2 minimum_size = Size2(720, 450) * EDSCALE;
const Size2 default_size = Size2(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT) * EDSCALE;

// Define a minimum window size to prevent UI elements from overlapping or being cut off.
Window *w = Object::cast_to<Window>(SceneTree::get_singleton()->get_root());
if (w) {
// Calling Window methods this early doesn't sync properties with DS.
w->set_min_size(minimum_size);
DisplayServer::get_singleton()->window_set_min_size(minimum_size);
if (!p_custom_res) {
// Only set window size if it currently matches the default, which is defined in `main/main.cpp`.
// This allows CLI arguments to override the window size.
w->set_size(default_size);
DisplayServer::get_singleton()->window_set_size(default_size);
}
}
Size2 real_size = DisplayServer::get_singleton()->window_get_size();

Expand All @@ -174,7 +167,6 @@ void ProjectManager::_update_size_limits(bool p_custom_res) {
Vector2i window_position;
window_position.x = screen_rect.position.x + (screen_rect.size.x - real_size.x) / 2;
window_position.y = screen_rect.position.y + (screen_rect.size.y - real_size.y) / 2;
DisplayServer::get_singleton()->window_set_position(window_position);

// Limit popup menus to prevent unusably long lists.
// We try to set it to half the screen resolution, but no smaller than the minimum window size.
Expand Down Expand Up @@ -1159,7 +1151,7 @@ void ProjectManager::_titlebar_resized() {

// Object methods.

ProjectManager::ProjectManager(bool p_custom_res) {
ProjectManager::ProjectManager() {
singleton = this;

set_translation_domain("godot.editor");
Expand Down Expand Up @@ -1189,7 +1181,7 @@ ProjectManager::ProjectManager(bool p_custom_res) {
switch (display_scale) {
case 0:
// Try applying a suitable display scale automatically.
EditorScale::set_scale(EditorSettings::get_singleton()->get_auto_display_scale());
EditorScale::set_scale(EditorSettings::get_auto_display_scale());
break;
case 1:
EditorScale::set_scale(0.75);
Expand Down Expand Up @@ -1747,7 +1739,7 @@ ProjectManager::ProjectManager(bool p_custom_res) {
title_bar->connect(SceneStringName(item_rect_changed), callable_mp(this, &ProjectManager::_titlebar_resized));
}

_update_size_limits(p_custom_res);
_update_size_limits();
}

ProjectManager::~ProjectManager() {
Expand Down
4 changes: 2 additions & 2 deletions editor/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ProjectManager : public Control {

Ref<Theme> theme;

void _update_size_limits(bool p_custom_res);
void _update_size_limits();
void _update_theme(bool p_skip_creation = false);
void _titlebar_resized();

Expand Down Expand Up @@ -262,7 +262,7 @@ class ProjectManager : public Control {

void add_new_tag(const String &p_tag);

ProjectManager(bool p_custom_res);
ProjectManager();
~ProjectManager();
};

Expand Down
57 changes: 54 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ static bool init_use_custom_pos = false;
static bool init_use_custom_screen = false;
static Vector2 init_custom_pos;
static int64_t init_embed_parent_window_id = 0;
static bool init_display_scale_found = false;
static int init_display_scale = 0;
static float init_custom_scale = 1.0;
static bool init_expand_to_title = false;
static bool use_custom_res = true;
static bool force_res = false;

Expand Down Expand Up @@ -2845,8 +2849,14 @@ Error Main::setup2(bool p_show_boot_logo) {
restore_editor_window_layout = value.operator int() == EditorSettings::InitialScreen::INITIAL_SCREEN_AUTO;
}
}

if (!prefer_wayland_found && assign == "run/platforms/linuxbsd/prefer_wayland") {
if (assign == "interface/editor/expand_to_title") {
init_expand_to_title = value;
} else if (assign == "interface/editor/display_scale") {
init_display_scale = value;
init_display_scale_found = true;
} else if (assign == "interface/editor/custom_display_scale") {
init_custom_scale = value;
} else if (!prefer_wayland_found && assign == "run/platforms/linuxbsd/prefer_wayland") {
prefer_wayland = value;
prefer_wayland_found = true;
}
Expand Down Expand Up @@ -2997,6 +3007,10 @@ Error Main::setup2(bool p_show_boot_logo) {
window_flags = DisplayServer::WINDOW_FLAG_BORDERLESS_BIT;
}

if ((project_manager || editor) && init_expand_to_title) {
window_flags |= DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE_BIT;
}

// rendering_driver now held in static global String in main and initialized in setup()
Error err;
display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_vsync_mode, window_flags, window_position, window_size, init_screen, context, init_embed_parent_window_id, err);
Expand Down Expand Up @@ -3049,6 +3063,43 @@ Error Main::setup2(bool p_show_boot_logo) {
return err;
}

if (project_manager && init_display_scale_found) {
float ui_scale = init_custom_scale;
switch (init_display_scale) {
case 0:
ui_scale = EditorSettings::get_auto_display_scale();

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

use of undeclared identifier 'EditorSettings'

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

use of undeclared identifier 'EditorSettings'

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

use of undeclared identifier 'EditorSettings'

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

use of undeclared identifier 'EditorSettings'

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

use of undeclared identifier 'EditorSettings'

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

use of undeclared identifier 'EditorSettings'

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'EditorSettings': is not a class or namespace name

Check failure on line 3070 in main/main.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'get_auto_display_scale': identifier not found
break;
case 1:
ui_scale = 0.75;
break;
case 2:
ui_scale = 1.0;
break;
case 3:
ui_scale = 1.25;
break;
case 4:
ui_scale = 1.5;
break;
case 5:
ui_scale = 1.75;
break;
case 6:
ui_scale = 2.0;
break;
default:
break;
}
if (!(force_res || use_custom_res)) {
display_server->window_set_size(window_size * ui_scale, DisplayServer::MAIN_WINDOW_ID);
}
Size2 real_size = DisplayServer::get_singleton()->window_get_size();
Rect2i scr_rect = display_server->screen_get_usable_rect(init_screen);
display_server->window_set_position(scr_rect.position + (scr_rect.size - real_size) / 2, DisplayServer::MAIN_WINDOW_ID);
}

display_server->show_window(DisplayServer::MAIN_WINDOW_ID);

if (display_server->has_feature(DisplayServer::FEATURE_ORIENTATION)) {
display_server->screen_set_orientation(window_orientation);
}
Expand Down Expand Up @@ -4285,7 +4336,7 @@ int Main::start() {
translation_server->get_editor_domain()->set_pseudolocalization_enabled(true);
}

ProjectManager *pmanager = memnew(ProjectManager(force_res || use_custom_res));
ProjectManager *pmanager = memnew(ProjectManager);
ProgressDialog *progress_dialog = memnew(ProgressDialog);
pmanager->add_child(progress_dialog);

Expand Down
1 change: 0 additions & 1 deletion platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6796,7 +6796,6 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
window_set_flag(WindowFlags(i), true, main_window);
}
}
show_window(main_window);

#if defined(RD_ENABLED)
if (rendering_context) {
Expand Down
1 change: 0 additions & 1 deletion platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3829,7 +3829,6 @@
window_set_flag(WindowFlags(i), true, main_window);
}
}
show_window(MAIN_WINDOW_ID);
force_process_and_drop_events();

#if defined(GLES3_ENABLED)
Expand Down
1 change: 0 additions & 1 deletion platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6898,7 +6898,6 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}

windows[MAIN_WINDOW_ID].initialized = true;
show_window(MAIN_WINDOW_ID);

#if defined(RD_ENABLED)
if (rendering_context) {
Expand Down

0 comments on commit a303e54

Please sign in to comment.