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

Only define keep_screen_on project setting once #64014

Merged
merged 1 commit into from
Aug 8, 2022
Merged
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
3 changes: 3 additions & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,9 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("display/window/size/window_height_override", 0);
custom_prop_info["display/window/size/window_height_override"] = PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"); // 8K resolution

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

GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
GLOBAL_DEF_RST("audio/general/2d_panning_strength", 1.0f);
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@
<member name="display/window/energy_saving/keep_screen_on" type="bool" setter="" getter="" default="true">
If [code]true[/code], keeps the screen on (even in case of inactivity), so the screensaver does not take over. Works on desktop and mobile platforms.
</member>
<member name="display/window/energy_saving/keep_screen_on.editor" type="bool" setter="" getter="" default="false">
Editor-only override for [member display/window/energy_saving/keep_screen_on]. Does not affect exported projects in debug or release mode.
</member>
<member name="display/window/handheld/orientation" type="int" setter="" getter="" default="0">
The default screen orientation to use on mobile devices. See [enum DisplayServer.ScreenOrientation] for possible values.
[b]Note:[/b] When set to a portrait orientation, this project setting does not flip the project resolution's width and height automatically. Instead, you have to set [member display/window/size/viewport_width] and [member display/window/size/viewport_height] accordingly.
Expand Down
1 change: 0 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->_allow_layered = false;
}

OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this might change behavior. I don't see the Android implementation querying the setting so it might break now.

I also wonder why it needs to be done manually in each platform instead of just done in main.cpp after the DisplaySerer is instantiated?

Copy link
Contributor Author

@RedMser RedMser Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the Android implementation querying the setting

Isn't this the android implementation? I also couldn't find any uses for the OS singleton's variable.

why it needs to be done manually in each platform

I'm not sure, maybe it was done this way since not all platforms implement the function? I could try changing how it's being called, but can't really test it for all platforms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the Android implementation querying the setting

Isn't this the android implementation? I also couldn't find any uses for the OS singleton's variable.

Ah indeed.

Ah I was going to suggest making OS::_keep_screen_on private but it seems like it's already the case, this was just abusing the fact that OS is a friend class to Main.

if (rtm == -1) {
rtm = GLOBAL_DEF("rendering/driver/threads/thread_model", OS::RENDER_THREAD_SAFE);
}
Expand Down
2 changes: 1 addition & 1 deletion platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}
#endif

bool keep_screen_on = bool(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
bool keep_screen_on = bool(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
screen_set_keep_on(keep_screen_on);

Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events);
Expand Down
2 changes: 1 addition & 1 deletion platform/linuxbsd/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4991,7 +4991,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode

#ifdef DBUS_ENABLED
screensaver = memnew(FreeDesktopScreenSaver);
screen_set_keep_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
screen_set_keep_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
#endif

r_error = OK;
Expand Down
2 changes: 1 addition & 1 deletion platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@ Point2i window_position(
}
#endif

screen_set_keep_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
screen_set_keep_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
}

DisplayServerMacOS::~DisplayServerMacOS() {
Expand Down
2 changes: 1 addition & 1 deletion platform/uwp/os_uwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
display_request->RequestActive();
}

set_keep_screen_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
set_keep_screen_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));

return OK;
}
Expand Down
2 changes: 1 addition & 1 deletion platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3653,7 +3653,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
tts = memnew(TTS_Windows);

// Enforce default keep screen on value.
screen_set_keep_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
screen_set_keep_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));

// Note: Wacom WinTab driver API for pen input, for devices incompatible with Windows Ink.
HMODULE wintab_lib = LoadLibraryW(L"wintab32.dll");
Expand Down