Merge pull request #58383 from bruvzg/no_inv_window_placement

This commit is contained in:
Rémi Verschelde 2022-04-27 09:33:40 +02:00 committed by GitHub
commit a19d7d8f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 70 deletions

View File

@ -98,6 +98,8 @@ Error EditorRun::run(const String &p_scene) {
screen_rect.position = DisplayServer::get_singleton()->screen_get_position(screen); screen_rect.position = DisplayServer::get_singleton()->screen_get_position(screen);
screen_rect.size = DisplayServer::get_singleton()->screen_get_size(screen); screen_rect.size = DisplayServer::get_singleton()->screen_get_size(screen);
int window_placement = EditorSettings::get_singleton()->get("run/window_placement/rect");
if (screen_rect != Rect2()) {
Size2 window_size; Size2 window_size;
window_size.x = ProjectSettings::get_singleton()->get("display/window/size/viewport_width"); window_size.x = ProjectSettings::get_singleton()->get("display/window/size/viewport_width");
window_size.y = ProjectSettings::get_singleton()->get("display/window/size/viewport_height"); window_size.y = ProjectSettings::get_singleton()->get("display/window/size/viewport_height");
@ -109,7 +111,6 @@ Error EditorRun::run(const String &p_scene) {
window_size = desired_size; window_size = desired_size;
} }
int window_placement = EditorSettings::get_singleton()->get("run/window_placement/rect");
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) { if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) {
bool hidpi_proj = ProjectSettings::get_singleton()->get("display/window/dpi/allow_hidpi"); bool hidpi_proj = ProjectSettings::get_singleton()->get("display/window/dpi/allow_hidpi");
int display_scale = 1; int display_scale = 1;
@ -160,6 +161,17 @@ Error EditorRun::run(const String &p_scene) {
args.push_back("--fullscreen"); args.push_back("--fullscreen");
} break; } 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; List<String> breakpoints;
EditorNode::get_editor_data().get_editor_breakpoints(&breakpoints); EditorNode::get_editor_data().get_editor_breakpoints(&breakpoints);

View File

@ -1365,6 +1365,12 @@ float EditorSettings::get_auto_display_scale() const {
return DisplayServer::get_singleton()->screen_get_max_scale(); return DisplayServer::get_singleton()->screen_get_max_scale();
#else #else
const int screen = DisplayServer::get_singleton()->window_get_current_screen(); 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. // 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); 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) { if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {

View File

@ -2877,18 +2877,16 @@ ProjectManager::ProjectManager() {
Vector2i screen_size = DisplayServer::get_singleton()->screen_get_size(); Vector2i screen_size = DisplayServer::get_singleton()->screen_get_size();
Vector2i screen_position = DisplayServer::get_singleton()->screen_get_position(); Vector2i screen_position = DisplayServer::get_singleton()->screen_get_position();
// Consider the editor display scale. window_size *= scale_factor;
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. DisplayServer::get_singleton()->window_set_size(window_size);
if (screen_size != Vector2i()) {
Vector2i window_position; Vector2i window_position;
window_position.x = screen_position.x + (screen_size.x - window_size.x) / 2; 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_position.y = screen_position.y + (screen_size.y - window_size.y) / 2;
DisplayServer::get_singleton()->window_set_size(window_size);
DisplayServer::get_singleton()->window_set_position(window_position); DisplayServer::get_singleton()->window_set_position(window_position);
} }
}
OS::get_singleton()->set_low_processor_usage_mode(true); OS::get_singleton()->set_low_processor_usage_mode(true);
} }

View File

@ -1045,7 +1045,9 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
Rect2i popup_rect; Rect2i popup_rect;
popup_rect.size = Vector2i(MIN(size_ratio.x, p_size.x), MIN(size_ratio.y, p_size.y)); popup_rect.size = Vector2i(MIN(size_ratio.x, p_size.x), MIN(size_ratio.y, p_size.y));
if (parent_rect != Rect2()) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2; popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
popup(popup_rect); popup(popup_rect);
} }
@ -1069,7 +1071,10 @@ void Window::popup_centered(const Size2i &p_minsize) {
Size2 contents_minsize = _get_contents_minimum_size(); Size2 contents_minsize = _get_contents_minimum_size();
popup_rect.size.x = MAX(p_minsize.x, contents_minsize.x); popup_rect.size.x = MAX(p_minsize.x, contents_minsize.x);
popup_rect.size.y = MAX(p_minsize.y, contents_minsize.y); popup_rect.size.y = MAX(p_minsize.y, contents_minsize.y);
if (parent_rect != Rect2()) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2; popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
popup(popup_rect); popup(popup_rect);
} }
@ -1091,8 +1096,10 @@ void Window::popup_centered_ratio(float p_ratio) {
} }
Rect2i popup_rect; Rect2i popup_rect;
if (parent_rect != Rect2()) {
popup_rect.size = parent_rect.size * p_ratio; popup_rect.size = parent_rect.size * p_ratio;
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2; popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
popup(popup_rect); popup(popup_rect);
} }