Previously, on Linux and BSD, inhibiting the screensaver was handled
using the org.freedesktop.ScreenSaver D-Bus API. Unfortunately, this API
is not available in a Flatpak sandbox. (This is because there is a
desire to tie inhibit sessions to a specific app and visible window; but
the org.freedesktop.ScreenSaver API does not support this.)
As a result, when using the Flatpak build of the Godot Editor (or a
Flatpak-ed build of a game) and using a controller to play a game, the
session will become idle after a few minutes.
The XDG desktop portal -- which is already used for color-picking, file
choosing, and querying the system theme -- has an Inhibit interface that
provides a superset of the functionality of the
org.freedesktop.ScreenSaver API, and is available to any sandboxed app.
Refactor code for making XDG portal requests that was previously
duplicated for the FileChooser and ColorPicker portal code. Check the
portal version to determine whether these portals can be used:
- FileChooser portal version 3 is required due to the use of the
"directory" parameter.
- On the Settings portal, the only addition in version 2 is the
ReadOne() method which is not used here, so version 1 suffices.
- On the Screenshot portal, the only addition in version 2 is the
"interactive" parameter to the Screenshot() method; this code only
uses the PickColor() method, so version 1 suffices.
Then, add support for the Inhibit portal. Use it if available and if
running in a sandbox. Prefer to use org.freedesktop.ScreenSaver if not
running in a sandbox, even if the portal is available, because (at least
in the GNOME 43 implementation of the portal) it does not work correctly
if the portal cannot map the request to a running app. This adds a small
amount of complexity to the implementation, but supporting both APIs is
necessary anyway (there are many systems in the wild that support
org.freedesktop.ScreenSaver but not the desktop portal).
Fixes https://github.com/godotengine/godot/issues/108634
On OS with Chinese locale, you might receive the following message
when running an editor using the `--verbose` option:
```
ERROR: Error on D-Bus communication: æªæ ¾å°è¯·æ±ç
设置
at: read_setting (platform/linuxbsd/freedesktop_portal_desktop.cpp:144)
```
usleep(3) was declared obsolete in POSIX.1-2001 and removed in POSIX.1-2008.
nanosleep(2) was recommended to be used instead.
`OS::delay_usec()` internally uses `nanosleep()`.
This also uses large number separators for improved readability.
This applies our existing style guide, and adds a new rule to that style
guide for modular components such as platform ports and modules:
Includes from the platform port or module should be included with relative
paths (relative to the root folder of the modular component, e.g.
`platform/linuxbsd/`), in their own section before Godot's "core" includes.
The `api` and `export` subfolders also need to be handled as self-contained
(and thus use relative paths for their "local" includes) as they are all
compiled for each editor platform, without necessarily having the api/export
matching platform folder in the include path.
E.g. the Linux editor build will compile `platform/android/{api,export}/*.cpp`
and those need to use relative includes for it to work.
Fixes two related segfaults caused by running the DBus version check
unconditionally and potentially calling null function pointers.
This was clearly an oversight as all the other wrappers have proper
loading status checks.
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.
It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).
We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).
Also fixed "cf." Frenchism - it's meant as "refer to / see".