Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - how to detect whether the application is running on GNOME or KDE?

I was wondering how I could do something like this (source) using Qt. I looked through the documentation but couldn't find any method to check if an external process is running.

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
like image 644
Jake Petroules Avatar asked Jul 31 '10 03:07

Jake Petroules


People also ask

How do I know if I am running GNOME or KDE?

You can determine the version of GNOME that is running on your system by going to the About panel in Settings. Open the Activities overview and start typing About. A window appears showing information about your system, including your distribution's name and the GNOME version.

Can Qt apps run on GNOME?

Qt apps run on GNOME Wayland have a non-matching window decoration look, even after setting a Qt theme.

How do I switch from GNOME to KDE?

Both Desktop Environment should be installed on your system. To switch between the two use the. To change it for all users, edit /etc/sysconfig/desktop and change the desktop from GNOME to KDE or vice versa.

Is KDE based on Qt?

KDE software is based on the Qt framework. In the early days of Qt, the KDE project and community were the biggest driving force in building the developer ecosystem around Qt. In the very early days, Qt was already dual-licensed, but the source code was available under proprietary open source licenses.


3 Answers

Normally you shouldn't do this. Generally, if your application behaves differently depending on desktop environment, that will be a nasty surprise for any user that switches between them.

The alternative

Use DE-agnostic commands like xdg-open. Advantages:

  • You don't have to write the logic yourself (xdg-utils already has done this)
  • More user-friendly. It follows the user's actual preferences; many users use one DE but prefer some applications from a different DE.
  • Supports other DEs like XFCE, LXDE, Unity, etc..

For example, instead of opening a URL in Firefox or Konqueror according to the currently-running DE, pass the URL to xdg-open to open it in the user's preferred application. (The user might be a Chromium user.) Don't hard-code nautilus or dolphin for GNOME and KDE; instead open the path using xdg-open.

Similarly, for other forms of interaction with the DE, try to use Freedesktop specifications, rather than trying to guess what DE is running. Standards exist for moving files to the trash, adding system tray applets, and adding files to the Recent Files list, among others.

like image 71
Mechanical snail Avatar answered Oct 06 '22 00:10

Mechanical snail


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

like image 32
schemacs Avatar answered Oct 06 '22 00:10

schemacs


I believe the correct way to do what pidof does is to look at entries in /proc. There's another thread on this here: Find PID of a Process by Name without Using popen() or system()

like image 25
siride Avatar answered Oct 06 '22 00:10

siride