Skip to content

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:

  1. Is it a good idea to make Godot dependent on D-Bus? I've added a DBUS_ENABLE define similar to PULSEAUDIO_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?

  2. 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?

  3. Does OS::_keep_screen_on have to be true 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 to true 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 to false and remove the hack?

  4. 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.

  5. 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.)

Merge request reports