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

Linux: Use D-Bus to inhibit screensaver #13076

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robxnano
Copy link

This is a fix for https://bugs.dolphin-emu.org/issues/10392, which has been a problem for at least 7 years now. I've implemented support for several D-Bus interfaces to inhibit the screensaver on Linux, which covers all the desktop environments that I could find that support it. As the xdg-screensaver method doesn't work at all any more, I've removed it completely.

As this uses Qt's D-Bus module, it requires dolphin-emu-nogui to be linked against libQt6DBus.so as well. This only happens if Dolphin is built with Qt enabled, otherwise it is simply skipped. If this isn't acceptable, I can move it into DolphinQt instead.

@JMC47
Copy link
Contributor

JMC47 commented Sep 26, 2024

@dolphin-emu-bot rebuild

@Tilka
Copy link
Member

Tilka commented Sep 27, 2024

Do you have any insight into why there is such a proliferation of different APIs?

@randomstuff
Copy link

randomstuff commented Sep 27, 2024

As the xdg-screensaver method doesn't work at all any more, I've removed it completely.

It doesn't? I mean, it's supposed to be a (messy) abstraction of what you are doing. It contains snippets such as:

        dbus-send --session \
                  --dest=org.freedesktop.ScreenSaver \
                  --type=method_call \
                  --print-reply \
                  --reply-timeout=2000 \
                  /ScreenSaver \
                  org.freedesktop.ScreenSaver.Inhibit \
                  string:$window_id \
                  string:xdg-screensaver \
                  | grep uint32 | cut -d ' ' -f 5 >| "$screensaver_file.cookie" \
                  2> /dev/null

which is actually what you are doing here: 643fc02#diff-729adc8bd1360f1b27c4ff23c72fb382d0d24e9c12f5ad937257894b6187c4e6R94

@robxnano
Copy link
Author

Do you have any insight into why there is such a proliferation of different APIs?

@Tilka The idle-inhibit spec (org.freedesktop.ScreenSaver) was supposed to be a unified effort by Gnome and KDE developers to replace their own (incompatible) APIs, but it hasn't been widely adopted by other desktop environments. The MATE and Xfce ones are just (IMHO unnecessary) forks of the older org.gnome.ScreenSaver interface. Then there's the XDG Desktop Portal (org.freedesktop.portal.Desktop) interface, which was designed to support sandboxing for Flatpak and has a few extra features. But again, the inhibit feature isn't widely supported outside KDE and Gnome yet, and the KDE implementation had a bug that prevented it from working until just last month.

In summary, it's just https://xkcd.com/927/. Hopefully in the future the portal API will become widely adopted and we can drop all the others.

@robxnano
Copy link
Author

@randomstuff The problem with the dbus-send method is that it runs as a separate executable so it can't keep the connection to the D-Bus socket open. That results in the session manager ending the inhibition immediately, as required by the specification:

Inhibition will stop when the UnInhibit method is called, or the application disconnects from the D-Bus session bus (which usually happens upon exit).

With this new change, the message is sent through the connection opened by Qt for other purposes, and kept open for the life of the application. This ensures the screensaver stays suspended for as long as necessary.

@theboreddevvv

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants