DevHeads.net

Writing C/C++ code to detect running desktop environment

I am working on implementing a piece of code that allows BOINC client
[1] to detect the desktop environment used by the user (mainly GNOME,
KDE Plasma, XFCE, LXDE/LXQT).
This feature will be needed for various reason that are off topic.

One idea is to use GDBus to scan DBus to detect the running d.e.
What do you think about?
Thank you

[1]: <a href="https://github.com/BOINC/boinc/tree/master/client" title="https://github.com/BOINC/boinc/tree/master/client">https://github.com/BOINC/boinc/tree/master/client</a>

Comments

Re: Writing C/C++ code to detect running desktop environment

By Kalev Lember at 05/29/2019 - 13:15

On Wed, May 29, 2019 at 7:11 PM Germano Massullo <germano. ... at gmail dot com>
wrote:

I would suggest reading the XDG_CURRENT_DESKTOP env variable. AFAIK all
major desktops support it and set it correctly for their sessions.

Kalev

Re: Writing C/C++ code to detect running desktop environment

By Stephen Gallagher at 05/29/2019 - 16:11

On Wed, May 29, 2019 at 1:16 PM Kalev Lember < ... at gmail dot com> wrote:
I realize you said that the reasons are off-topic, but in general I'd
recommend not making desktop-specific decisions at a high-level and
instead base your decisions off of availability of particular
functionality. For example, if your application needs to manage
software updates, have it check for whether PackageKit or dnf-daemon
are available. If it needs to store something in a password wallet,
check for GNOME Keyring or KWallet, etc.

Among other things, it means that alternative desktops that share some
tools with the popular ones don't have to get special code to work
with your project.

Re: Writing C/C++ code to detect running desktop environment

By Germano Massullo at 05/29/2019 - 19:01

Il giorno mer 29 mag 2019 alle ore 22:12 Stephen Gallagher
< ... at redhat dot com> ha scritto:
I need to retrieve user idle time. To achieve this I was using GDbus
API of GLib/GIO to retrieve the systemd-logind IdleSinceHint DBus
property, but I have been told that logind relies on desktop
environment to pass the information to update this property. None of
main desktop environments does it, so I am writing code that will
interact with specific d.e. to retrieve user idle time. More infos at
"[systemd-devel] interacting with logind to detect user idle time"[1]

[1]: <a href="https://lists.freedesktop.org/archives/systemd-devel/2019-May/042496.html" title="https://lists.freedesktop.org/archives/systemd-devel/2019-May/042496.html">https://lists.freedesktop.org/archives/systemd-devel/2019-May/042496.html</a>

Re: Writing C/C++ code to detect running desktop environment

By Kevin Kofler at 05/29/2019 - 17:01

Stephen Gallagher wrote:
Another solution is to use abstraction layers. E.g., for the password
wallet, you can use QtKeychain: <a href="https://github.com/frankosterfeld/qtkeychain" title="https://github.com/frankosterfeld/qtkeychain">https://github.com/frankosterfeld/qtkeychain</a>
To open a document or web page, instead of hardcoding the application (e.g.,
the web browser), you can run xdg-open. Etc.

Kevin Kofler