Make "Keep screen on" work on Linux
This pull request adds keep_screen_on
support for Linux through the org.freedesktop.ScreenSaver
D-Bus service which is supported by most desktop environments as a way to keep the screen from turning off after a certain period of inactivity.
This is my first time contributing to Godot and the first time implementing something non-trivial in C++, so here are some things I'm not sure about yet:
-
Is it a good idea to make Godot dependent on D-Bus? I've added a
DBUS_ENABLE
define similar toPULSEAUDIO_ENABLED
, so that Godot can be built without D-Bus development libraries but games using the regular Godot build will still crash if D-Bus isn't installed. All the desktop distributions I know ship with D-Bus, but can we assume that this is the case for all users? -
Is my "error handling" sufficient? Because some desktop environments might not have implemented the
org.freedesktop.ScreenSaver
service, I added some basic error handling (if you can call it that) to disable the feature and do nothing on future calls if a D-Bus interaction fails. Is that enough? -
Does
OS::_keep_screen_on
have to betrue
by default? Because this variable represent whether the feature is currently initialized (and not just enabled in the settings) I don't see any reason for it be totrue
by default. This has only resulted in a weird hack (enabling an "already enabled" feature) and the comment next to it ("because this had been true before godot 2.0") doesn't exactly help. Is there any reason for me not to change this tofalse
and remove the hack? -
Should "Keep screen on" be enabled for the editor itself? I'm currently only enabling the feature when running the game because I feel like this behavior isn't expected from an editor, but I'm not sure.
-
Am I doing anything horribly wrong? As I said, I'm just starting out with C++, so I might have messed up some really basic things. If that's the case, please let me know!
I'm happy to hear any kind of feedback on this PR.
(I'll remove the print_line
's and add the copyright headers once everything has been reviewed.)