X Tutup
Skip to content

Support XDG Inhibit portal#108704

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
wjt:xdg-portal-inhibit
Nov 24, 2025
Merged

Support XDG Inhibit portal#108704
Repiteo merged 1 commit intogodotengine:masterfrom
wjt:xdg-portal-inhibit

Conversation

@wjt
Copy link
Contributor

@wjt wjt commented Jul 17, 2025

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.

Add support for this API to the FreeDesktopPortalDesktop class. 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 #108634

@wjt wjt requested a review from a team as a code owner July 17, 2025 11:43
@wjt wjt marked this pull request as draft July 17, 2025 11:43
@wjt wjt force-pushed the xdg-portal-inhibit branch from 3993626 to 9c31577 Compare July 17, 2025 12:21
@AThousandShips AThousandShips added this to the 4.5 milestone Jul 28, 2025
wjt added a commit to endlessm/threadbare that referenced this pull request Aug 11, 2025
Current Godot releases support using org.freedesktop.ScreenSaver to
inhibit the screensaver, but do not support using the Inhibit portal.

I have implemented Inhibit portal support upstream, but it is awaiting
review; and since it missed the 4.5 feature freeze it will not be part
of a Godot release until 4.6, which is probably close to a year away.

godotengine/godot#108704
@AThousandShips AThousandShips modified the milestones: 4.5, 4.6 Sep 14, 2025
wjt added a commit to wjt/org.godotengine.Godot that referenced this pull request Sep 16, 2025
This is necessary because Godot does not know how to use the Inhibit
portal to inhibit the screensaver.
godotengine/godot#108634

I have implemented this in a PR that I hope to land for Godot 4.6
godotengine/godot#108704

In the meantime, allow the editor to talk to
org.freedesktop.ScreenSaver. This will require approval from Flathub reviewers but I am confident
this exception will be accepted because:

a. it was accepted for a game I co-maintain;
b. there is a solution in progress;
c. the editor has host filesystem access and the ability to spawn
   commands on the host, so this new flag does not meaningfully reduce
   the sandboxing.
@wjt wjt force-pushed the xdg-portal-inhibit branch from 9c31577 to 64b503b Compare September 16, 2025 10:19
@wjt
Copy link
Contributor Author

wjt commented Sep 16, 2025

I have rebased this branch (and its parent) and resolved conflicts due to commit 0edb6bd.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally, it works as expected (outside a Flatpak). Code looks good to me.

Operating System: Fedora Linux 42
KDE Plasma Version: 6.4.4
KDE Frameworks Version: 6.17.0
Qt Version: 6.9.1
Kernel Version: 6.16.7-200.fc42.x86_64 (64-bit)
Graphics Platform: X11

Processors: 32 × AMD Ryzen 9 9950X3D 16-Core Processor
Memory: 64 GiB of RAM (62.3 GiB usable)
Graphics Processor: NVIDIA GeForce RTX 5090
Manufacturer: Micro-Star International Co., Ltd.
Product Name: MS-7E49
System Version: 1.0

@wjt
Copy link
Contributor Author

wjt commented Sep 16, 2025

Thanks for testing! Since you were testing outside a Flatpak, you have tested that the code prefers to use the existing API in that case:

		// If not sandboxed, prefer to use org.freedesktop.Screenshot
		supported = OS::get_singleton()->is_sandboxed() && _is_interface_supported(BUS_INTERFACE_INHIBIT, 1);

@wjt wjt marked this pull request as ready for review September 22, 2025 16:16
@Repiteo Repiteo requested a review from bruvzg September 23, 2025 01:06
@wjt
Copy link
Contributor Author

wjt commented Oct 21, 2025

I have just re-read https://contributing.godotengine.org/en/latest/organization/pull_requests/review_guidelines.html#git-checklist and noticed this section:

Make sure that the PR comes in one commit.

When each commit is self-contained and could be used to build a clean and working version of the engine, it may be okay to merge a pull request with multiple commits, but in general, we require that all pull requests only have one commit. This helps us keep the Git history clean.

This PR is 5 commits. I have taken care that each commit is logically independent, can be built individually, and makes a distinct change, but if preferred I can squash this down into fewer commits.

wjt added a commit to wjt/godot-docs that referenced this pull request Oct 21, 2025
Since godotengine/godot#108704, the sentence
about Flatpak is fully obsolete:

1. All standard Flatpak runtimes contain libdbus;
2. With the addition of support for the XDG Inhibit portal, Godot is
   able to inhibit idle without any sandboxing adjustments.

More generally, I don't think we need to mention that D-Bus is required
to inhibit idle, even outside Flatpak: practically speaking, all desktop
Linux systems have had libdbus available for 20+ years.

Remove the whole paragraph.
@AThousandShips
Copy link
Member

Squashing the commits isn't necessary until this is ready to merge, but it should be a single commit for merger, we only merge multiple commits in very specific cases when the changes can be completely separated from each other or for practical reasons like ignoring for git blame

@wjt
Copy link
Contributor Author

wjt commented Oct 21, 2025

OK! I look forward to making whatever changes are needed to make this ready to merge :)

@wjt wjt force-pushed the xdg-portal-inhibit branch from ff4ed08 to e080eb9 Compare October 21, 2025 09:38
@wjt wjt force-pushed the xdg-portal-inhibit branch from e080eb9 to 3994c4a Compare October 21, 2025 09:43
@wjt
Copy link
Contributor Author

wjt commented Oct 21, 2025

Thanks! I infer that the convention is r_ for reference parameters and p_ for other parameters, but I couldn't find this in the style guide at https://docs.godotengine.org/en/4.4/contributing/development/code_style_guidelines.html#c-and-objective-c, and clang-format doesn't seem to enforce it. Is the style documented? (NP if not, I'm just wondering what I missed.)

@AThousandShips
Copy link
Member

That standard is here

@wjt wjt force-pushed the xdg-portal-inhibit branch from 3994c4a to 704e196 Compare October 21, 2025 09:53
@wjt
Copy link
Contributor Author

wjt commented Oct 21, 2025

Thanks for your help! I have collapsed this down into one commit, folding the important parts of the other commit messages into it.

@wjt wjt force-pushed the xdg-portal-inhibit branch from 704e196 to de4fb0b Compare October 21, 2025 10:50
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 godotengine#108634
@wjt wjt force-pushed the xdg-portal-inhibit branch from de4fb0b to 1a3a254 Compare November 17, 2025 12:37
@wjt
Copy link
Contributor Author

wjt commented Nov 17, 2025

Rebased & fixed conflicts introduced by #112629 last week.

Is there anything else I can do here to help get this into a dev snapshot of 4.6? It'd be nice to be able to update the flathub-beta channel to a snapshot including this change sooner rather than later, so it can get a bit more testing in the wild.

@deralmas
Copy link
Contributor

Hi, it got approved, so I think it's just a matter of time.

@Repiteo Repiteo merged commit e1b3387 into godotengine:master Nov 24, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 24, 2025

Thanks!

@wjt wjt deleted the xdg-portal-inhibit branch November 25, 2025 09:56
wjt added a commit to wjt/org.godotengine.Godot that referenced this pull request Dec 2, 2025
Because 4.6~dev5 is considered newer than 4.6~beta1 by AppStream (d >
b), the ~~ syntax is needed to avoid errors when we later update to
~beta. (And in turn the -betas must use ~ so that 4.6~beta1 sorts before
4.6.)

--talk-name=org.freedesktop.ScreenSaver is no longer needed:
godotengine/godot#108704.
wjt added a commit to wjt/org.godotengine.Godot that referenced this pull request Jan 29, 2026
Godot 4.6 supports using the Inhibit portal
<godotengine/godot#108704> so this is no longer
necessary.
Calinou pushed a commit to flathub/org.godotengine.Godot that referenced this pull request Feb 3, 2026
Godot 4.6 supports using the Inhibit portal
<godotengine/godot#108704> so this is no longer
necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inhibiting screensaver does not work in Flatpak sandbox

6 participants

X Tutup