Qt - how to determine if an application is running in GNOME or KDE?

I was wondering how I could do something like this ( source ) using Qt. I looked through the documentation, but could not find any way to check if the external process is working.

if [ "$(pidof ksmserver)" ]; then echo "KDE running." # KDE-specific stuff here elif [ "$(pidof gnome-session)" ]; then echo "GNOME running." # GNOME-specific stuff here elif [ "$(pidof xfce-mcs-manage)" ]; then echo "Xfce running." # Xfce-specific stuff here fi 
+4
source share
3 answers

Use QProcess to run pidof foo and then check its stdout? If this is not what you want, search for /proc/ .

+2
source

Usually you should not do this. As a rule, if your application behaves differently depending on the desktop environment, this will be an unpleasant surprise for any user who switches between them.

Alternative

Use DE-agnostic commands such as xdg-open . Benefits:

  • You do not need to write logic yourself (xdg-utils already did this)
  • More comfortable. It matches the actual preferences of the user; many users use one DE, but prefer some applications from another DE.
  • Supports other DEs such as XFCE, LXDE, Unity, etc.

For example, instead of opening the URL in Firefox or Konqueror according to the current DE, pass the xdg-open URL to open it in your preferred application. (The user may be a Chromium user.) Do not use hard-code nautilus or dolphin for GNOME and KDE; open the path using xdg-open instead.

Similarly, for other forms of interacting with DE, try to use the Freedesktop specifications , rather than trying to guess what DE is. There are standards for moving files to the trash , adding taskbar applets, and adding files to the list of recent files. Among others.

+4
source

I believe that the correct way to do what pidof does is to look at the entries in / proc. There is another thread here: Find the process PID by name without using popen () or system ()

+1
source

All Articles