Search code examples
clinuxdesktopenvironment

Detect desktop environment in Linux programmatically in C


I am trying to detect whether I am running on a Gnome or KDE desktop environment.

I know I can check via a ps -aux and grepping either gnome or KDE but that's not good: 1) what if I am on a gnome desktop but I have the KDE libs loaded? 2) I need to do it from code without using system() or popen() or other fork/exec combination.

I can read files, or env. variables or whatever.

Any ideas?

thanks, any help is appreciated.


Solution

  • Pick a set of window managers you care about: metacity, xfwm4, flwm, etc. You can look for those in your grep of ps (or search through /proc). Gnome libraries don't necessarily mean that someone's running the whole gnome desktop environment, but then Gnome and KDE aren't window managers. If WMs are what you care about, look for those.