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

Add minimum / maximum window size project setting #80337

Closed
wants to merge 1 commit into from
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
8 changes: 7 additions & 1 deletion core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,8 @@ ProjectSettings::ProjectSettings() {
// The default window size is tuned to:
// - Have a 16:9 aspect ratio,
// - Have both dimensions divisible by 8 to better play along with video recording,
// - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings).
// - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings),
// - Have a minimum size of 64x64 to prevent issues that can arise when the window is resized to a near-zero size. (GH-37242)
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 1152); // 8K resolution
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 648); // 8K resolution

Expand All @@ -1298,6 +1299,11 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution

GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_minimum_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 64);
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_minimum_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 64);
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_maximum_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0);
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_maximum_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0);

GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
GLOBAL_DEF("display/window/energy_saving/keep_screen_on.editor", false);

Expand Down
14 changes: 14 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,20 @@
On desktop platforms, overrides the game's initial window width. See also [member display/window/size/window_height_override], [member display/window/size/viewport_width] and [member display/window/size/viewport_height].
[b]Note:[/b] By default, or when set to [code]0[/code], the initial window width is the viewport [member display/window/size/viewport_width]. This setting is ignored on iOS, Android, and Web.
</member>
<member name="display/window/size/window_minimum_width" type="int" setter="" getter="" default="64">
On desktop platforms, sets the game's minimum window width.
[b]Note:[/b] By default, the main window has a minimum width and height of [code]64[/code]. This prevents issues that can arise when the window is resized to a near-zero size.
</member>
<member name="display/window/size/window_minimum_height" type="int" setter="" getter="" default="64">
On desktop platforms, sets the game's minimum window height.
[b]Note:[/b] By default, the main window has a minimum width and height of [code]64[/code]. This prevents issues that can arise when the window is resized to a near-zero size.
</member>
<member name="display/window/size/window_maximum_width" type="int" setter="" getter="" default="0">
On desktop platforms, sets the game's maximum window width. If set to [code]0[/code], the setting is ignored.
</member>
<member name="display/window/size/window_maximum_height" type="int" setter="" getter="" default="0">
On desktop platforms, sets the game's maximum window height. If set to [code]0[/code], the setting is ignored.
</member>
<member name="display/window/stretch/aspect" type="String" setter="" getter="" default="&quot;keep&quot;">
</member>
<member name="display/window/stretch/mode" type="String" setter="" getter="" default="&quot;disabled&quot;">
Expand Down
42 changes: 33 additions & 9 deletions editor/editor_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,41 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) {

int window_placement = EDITOR_GET("run/window_placement/rect");
if (screen_rect != Rect2()) {
Size2 window_size;
window_size.x = GLOBAL_GET("display/window/size/viewport_width");
window_size.y = GLOBAL_GET("display/window/size/viewport_height");

Size2 desired_size;
desired_size.x = GLOBAL_GET("display/window/size/window_width_override");
desired_size.y = GLOBAL_GET("display/window/size/window_height_override");
if (desired_size.x > 0 && desired_size.y > 0) {
window_size = desired_size;
const int window_width_override = GLOBAL_GET("display/window/size/window_width_override");
const int window_height_override = GLOBAL_GET("display/window/size/window_height_override");

const int viewport_width = GLOBAL_GET("display/window/size/viewport_width");
const int viewport_height = GLOBAL_GET("display/window/size/viewport_height");

const int window_minimum_width = GLOBAL_GET("display/window/size/window_minimum_width");
const int window_minimum_height = GLOBAL_GET("display/window/size/window_minimum_height");
const int window_maximum_width = GLOBAL_GET("display/window/size/window_maximum_width");
const int window_maximum_height = GLOBAL_GET("display/window/size/window_maximum_height");

int desired_width = viewport_width;
int desired_height = viewport_height;

if (window_width_override != 0) {
desired_width = window_width_override;
}
if (window_height_override != 0) {
desired_height = window_height_override;
}

if (window_maximum_width != 0) {
desired_width = MIN(desired_width, window_maximum_width);
}
if (window_maximum_height != 0) {
desired_height = MIN(desired_height, window_maximum_height);
}

desired_width = MAX(desired_width, window_minimum_width);
desired_height = MAX(desired_height, window_minimum_height);

Size2 window_size;
window_size.x = desired_width;
window_size.y = desired_height;

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_HIDPI)) {
bool hidpi_proj = GLOBAL_GET("display/window/dpi/allow_hidpi");
int display_scale = 1;
Expand Down
45 changes: 32 additions & 13 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,20 +1808,39 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph

if (use_custom_res) {
if (!force_res) {
window_size.width = GLOBAL_GET("display/window/size/viewport_width");
window_size.height = GLOBAL_GET("display/window/size/viewport_height");

if (globals->has_setting("display/window/size/window_width_override") &&
globals->has_setting("display/window/size/window_height_override")) {
int desired_width = globals->get("display/window/size/window_width_override");
if (desired_width > 0) {
window_size.width = desired_width;
}
int desired_height = globals->get("display/window/size/window_height_override");
if (desired_height > 0) {
window_size.height = desired_height;
}
const int window_width_override = GLOBAL_GET("display/window/size/window_width_override");
const int window_height_override = GLOBAL_GET("display/window/size/window_height_override");

const int viewport_width = GLOBAL_GET("display/window/size/viewport_width");
const int viewport_height = GLOBAL_GET("display/window/size/viewport_height");

const int window_minimum_width = GLOBAL_GET("display/window/size/window_minimum_width");
const int window_minimum_height = GLOBAL_GET("display/window/size/window_minimum_height");
const int window_maximum_width = GLOBAL_GET("display/window/size/window_maximum_width");
const int window_maximum_height = GLOBAL_GET("display/window/size/window_maximum_height");

int desired_width = viewport_width;
int desired_height = viewport_height;

if (window_width_override != 0) {
desired_width = window_width_override;
}
if (window_height_override != 0) {
desired_height = window_height_override;
}

if (window_maximum_width != 0) {
desired_width = MIN(desired_width, window_maximum_width);
}
if (window_maximum_height != 0) {
desired_height = MIN(desired_height, window_maximum_height);
}

desired_width = MAX(desired_width, window_minimum_width);
desired_height = MAX(desired_height, window_minimum_height);

window_size.width = desired_width;
window_size.height = desired_height;
}

if (!bool(GLOBAL_GET("display/window/size/resizable"))) {
Expand Down
8 changes: 7 additions & 1 deletion scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,14 @@ SceneTree::SceneTree() {

// Create with mainloop.

const int viewport_minimum_width = GLOBAL_GET("display/window/size/window_minimum_width");
const int viewport_minimum_height = GLOBAL_GET("display/window/size/window_minimum_height");
const int viewport_maximum_width = GLOBAL_GET("display/window/size/window_maximum_width");
const int viewport_maximum_height = GLOBAL_GET("display/window/size/window_maximum_height");

root = memnew(Window);
root->set_min_size(Size2i(64, 64)); // Define a very small minimum window size to prevent bugs such as GH-37242.
root->set_min_size(Size2i(viewport_minimum_width, viewport_minimum_height));
root->set_max_size(Size2i(viewport_maximum_width, viewport_maximum_height));
root->set_process_mode(Node::PROCESS_MODE_PAUSABLE);
root->set_name("root");
root->set_title(GLOBAL_GET("application/config/name"));
Expand Down