summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-02-21 10:17:28 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-04-20 11:10:33 +0300
commitdefcd0c57e8b90177639963e958ea91be4c511bc (patch)
treefc461370784c8f8241758f1936609b63b010dac1 /editor
parentf4b0c7a1ea8d86c1dfd96478ca12ad1360903d9d (diff)
Avoid setting sub-window or started project window positions, if it's impossible to get screen rect.
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_run.cpp122
-rw-r--r--editor/editor_settings.cpp6
-rw-r--r--editor/project_manager.cpp16
3 files changed, 80 insertions, 64 deletions
diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp
index 574acdff1c..6a2ff50ee0 100644
--- a/editor/editor_run.cpp
+++ b/editor/editor_run.cpp
@@ -98,67 +98,79 @@ Error EditorRun::run(const String &p_scene) {
screen_rect.position = DisplayServer::get_singleton()->screen_get_position(screen);
screen_rect.size = DisplayServer::get_singleton()->screen_get_size(screen);
- Size2 window_size;
- window_size.x = ProjectSettings::get_singleton()->get("display/window/size/viewport_width");
- window_size.y = ProjectSettings::get_singleton()->get("display/window/size/viewport_height");
-
- Size2 desired_size;
- desired_size.x = ProjectSettings::get_singleton()->get("display/window/size/window_width_override");
- desired_size.y = ProjectSettings::get_singleton()->get("display/window/size/window_height_override");
- if (desired_size.x > 0 && desired_size.y > 0) {
- window_size = desired_size;
- }
-
int window_placement = EditorSettings::get_singleton()->get("run/window_placement/rect");
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) {
- bool hidpi_proj = ProjectSettings::get_singleton()->get("display/window/dpi/allow_hidpi");
- int display_scale = 1;
+ if (screen_rect != Rect2()) {
+ Size2 window_size;
+ window_size.x = ProjectSettings::get_singleton()->get("display/window/size/viewport_width");
+ window_size.y = ProjectSettings::get_singleton()->get("display/window/size/viewport_height");
+
+ Size2 desired_size;
+ desired_size.x = ProjectSettings::get_singleton()->get("display/window/size/window_width_override");
+ desired_size.y = ProjectSettings::get_singleton()->get("display/window/size/window_height_override");
+ if (desired_size.x > 0 && desired_size.y > 0) {
+ window_size = desired_size;
+ }
- if (OS::get_singleton()->is_hidpi_allowed()) {
- if (hidpi_proj) {
- display_scale = 1; // Both editor and project runs in hiDPI mode, do not scale.
- } else {
- display_scale = DisplayServer::get_singleton()->screen_get_max_scale(); // Editor is in hiDPI mode, project is not, scale down.
- }
- } else {
- if (hidpi_proj) {
- display_scale = (1.f / DisplayServer::get_singleton()->screen_get_max_scale()); // Editor is not in hiDPI mode, project is, scale up.
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) {
+ bool hidpi_proj = ProjectSettings::get_singleton()->get("display/window/dpi/allow_hidpi");
+ int display_scale = 1;
+
+ if (OS::get_singleton()->is_hidpi_allowed()) {
+ if (hidpi_proj) {
+ display_scale = 1; // Both editor and project runs in hiDPI mode, do not scale.
+ } else {
+ display_scale = DisplayServer::get_singleton()->screen_get_max_scale(); // Editor is in hiDPI mode, project is not, scale down.
+ }
} else {
- display_scale = 1; // Both editor and project runs in lowDPI mode, do not scale.
+ if (hidpi_proj) {
+ display_scale = (1.f / DisplayServer::get_singleton()->screen_get_max_scale()); // Editor is not in hiDPI mode, project is, scale up.
+ } else {
+ display_scale = 1; // Both editor and project runs in lowDPI mode, do not scale.
+ }
}
+ screen_rect.position /= display_scale;
+ screen_rect.size /= display_scale;
}
- screen_rect.position /= display_scale;
- screen_rect.size /= display_scale;
- }
- switch (window_placement) {
- case 0: { // top left
- args.push_back("--position");
- args.push_back(itos(screen_rect.position.x) + "," + itos(screen_rect.position.y));
- } break;
- case 1: { // centered
- Vector2 pos = (screen_rect.position) + ((screen_rect.size - window_size) / 2).floor();
- args.push_back("--position");
- args.push_back(itos(pos.x) + "," + itos(pos.y));
- } break;
- case 2: { // custom pos
- Vector2 pos = EditorSettings::get_singleton()->get("run/window_placement/rect_custom_position");
- pos += screen_rect.position;
- args.push_back("--position");
- args.push_back(itos(pos.x) + "," + itos(pos.y));
- } break;
- case 3: { // force maximized
- Vector2 pos = screen_rect.position;
- args.push_back("--position");
- args.push_back(itos(pos.x) + "," + itos(pos.y));
- args.push_back("--maximized");
- } break;
- case 4: { // force fullscreen
- Vector2 pos = screen_rect.position;
- args.push_back("--position");
- args.push_back(itos(pos.x) + "," + itos(pos.y));
- args.push_back("--fullscreen");
- } break;
+ switch (window_placement) {
+ case 0: { // top left
+ args.push_back("--position");
+ args.push_back(itos(screen_rect.position.x) + "," + itos(screen_rect.position.y));
+ } break;
+ case 1: { // centered
+ Vector2 pos = (screen_rect.position) + ((screen_rect.size - window_size) / 2).floor();
+ args.push_back("--position");
+ args.push_back(itos(pos.x) + "," + itos(pos.y));
+ } break;
+ case 2: { // custom pos
+ Vector2 pos = EditorSettings::get_singleton()->get("run/window_placement/rect_custom_position");
+ pos += screen_rect.position;
+ args.push_back("--position");
+ args.push_back(itos(pos.x) + "," + itos(pos.y));
+ } break;
+ case 3: { // force maximized
+ Vector2 pos = screen_rect.position;
+ args.push_back("--position");
+ args.push_back(itos(pos.x) + "," + itos(pos.y));
+ args.push_back("--maximized");
+ } break;
+ case 4: { // force fullscreen
+ Vector2 pos = screen_rect.position;
+ args.push_back("--position");
+ args.push_back(itos(pos.x) + "," + itos(pos.y));
+ args.push_back("--fullscreen");
+ } break;
+ }
+ } else {
+ // Unable to get screen info, skip setting position.
+ switch (window_placement) {
+ case 3: { // force maximized
+ args.push_back("--maximized");
+ } break;
+ case 4: { // force fullscreen
+ args.push_back("--fullscreen");
+ } break;
+ }
}
List<String> breakpoints;
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 48f04694aa..bdabff20f9 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -1365,6 +1365,12 @@ float EditorSettings::get_auto_display_scale() const {
return DisplayServer::get_singleton()->screen_get_max_scale();
#else
const int screen = DisplayServer::get_singleton()->window_get_current_screen();
+
+ if (DisplayServer::get_singleton()->screen_get_size(screen) == Vector2i()) {
+ // Invalid screen size, skip.
+ return 1.0;
+ }
+
// Use the smallest dimension to use a correct display scale on portrait displays.
const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 4ca0f18f0e..da57efd1bb 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -2877,17 +2877,15 @@ ProjectManager::ProjectManager() {
Vector2i screen_size = DisplayServer::get_singleton()->screen_get_size();
Vector2i screen_position = DisplayServer::get_singleton()->screen_get_position();
- // Consider the editor display scale.
- window_size.x = round((float)window_size.x * scale_factor);
- window_size.y = round((float)window_size.y * scale_factor);
-
- // Make the window centered on the screen.
- Vector2i window_position;
- window_position.x = screen_position.x + (screen_size.x - window_size.x) / 2;
- window_position.y = screen_position.y + (screen_size.y - window_size.y) / 2;
+ window_size *= scale_factor;
DisplayServer::get_singleton()->window_set_size(window_size);
- DisplayServer::get_singleton()->window_set_position(window_position);
+ if (screen_size != Vector2i()) {
+ Vector2i window_position;
+ window_position.x = screen_position.x + (screen_size.x - window_size.x) / 2;
+ window_position.y = screen_position.y + (screen_size.y - window_size.y) / 2;
+ DisplayServer::get_singleton()->window_set_position(window_position);
+ }
}
OS::get_singleton()->set_low_processor_usage_mode(true);