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 Germano Massullo at 06/03/2019 - 10:25

A dubt about XDG_CURRENT_DESKTOP. Since boinc-client runs as a service
with its own user, I don't think it will be able to read
XDG_CURRENT_DESKTOP defined in other users sessions. Therefore IMHO I
need another kind of solution

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

By =?iso-8859-1?q?... at 06/04/2019 - 11:29

Germano Massullo wrote:
So the question isn't what desktop the user is using, but rather what
desktops, if any, other users on the machine are using. Have you
confirmed that you're able to query another user's desktop session once
you know which desktop it is? The ability to do such things should be
quite limited for security reasons, even though Boinc has a legitimate
use case.

Björn Persson

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

By Germano Massullo at 06/04/2019 - 11:56

Il giorno mar 4 giu 2019 alle ore 17:31 Björn Persson
<Bjorn@rombobjörn.se> ha scritto:
Well when I started the thread I had not thought that BOINC client
service is running on a confined user.

I cannot read XDG_CURRENT_DESKTOP of other users. I am actually
wondering if checking for specific executables [1] [2] would be the
best idea

[1]: like for example /usr/bin/plasmashell
[2]: or scanning running processes

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

By =?iso-8859-1?q?... at 06/04/2019 - 12:59

Germano Massullo skrev:
If you solve that problem, then as the next step you'll want to query
the session: Is it active or idle? I'll be surprised if you can do that
to another user's session without help from some privileged service.

Björn Persson

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

By Germano Massullo at 06/05/2019 - 03:10

Il giorno mar 4 giu 2019 alle ore 19:00 Björn Persson
<Bjorn@rombobjörn.se> ha scritto:
I'll be surprised if you can do that
That is a very good question, thank you for pointing it out. I will let you know

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