7

I need to programatically determine which window manager is running, on Linux.

Pseudocode for how it would be used:

if(WindowManagerOfOS.isKDE()){
      do.anyThing();
}

How can I do this? Is it even possible?

Mechanical snail
  • 29,755
  • 14
  • 88
  • 113
Carlos Spohr
  • 507
  • 11
  • 24
  • 1
    I can't test this on my computer but try seeing what UIManager.getSystemLookAndFeelClassName() returns on either one – Adam Apr 19 '12 at 19:17
  • Related: http://stackoverflow.com/questions/3376679/qt-how-to-detect-whether-the-application-is-running-on-gnome-or-kde – Mechanical snail Sep 19 '12 at 17:36

2 Answers2

10
System.getenv("XDG_CURRENT_DESKTOP")

returns "GNOME" on my machine. Try it out on KDE-based box.

See also

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • A user could have both installed, but only run one in which case both environment variables would be present. You'd have to check the running processes. – Adam Apr 19 '12 at 19:18
  • Tomaz, i will use the 'KDE_SESSION_VERSION' to check this. The problem is the KDE dont have a Desktop... – Carlos Spohr Apr 19 '12 at 19:32
  • 1
    I'm forgot comment...System.getenv("XDG_CURRENT_DESKTOP") prints null for me in Linux Mint 12 with KDE native. – Carlos Spohr Apr 19 '12 at 19:39
  • 4
    No, this is deprecated, don't use it. It's unset on Gnome3/Fedora16 also. – Andy Ross Apr 19 '12 at 21:38
1

The official answer is that you aren't supposed to care. Both desktops honor existing standards. Both can run each others' software. What is it you are trying to do? If it's a particular service you are looking for that only one distribution ships by default, you should be probing for that instead.

Andy Ross
  • 11,699
  • 1
  • 34
  • 31
  • 5
    -1 This isn't an answer to the question and should have been a comment. – jobukkit Sep 03 '13 at 10:40
  • I'm going to vote that this is an ok answer. Maybe not the best, but it works because sometimes we need to say "Don't do that" when people want to know how to "do that." – Russia Must Remove Putin May 04 '14 at 16:35
  • 1
    There are various places where people do care and should know, the first example is within xdg-utils http://cgit.freedesktop.org/xdg/xdg-utils/tree/scripts/xdg-utils-common.in see detectDE(), it is used by xdg-su/xdg-terminal etc to work out which shell our graphical sudo wrapper should be used. There are also some things such as setting a wallpaper etc that are not covered by any fixed api or standard. The variety wallpaper application does just that in the following script http://bazaar.launchpad.net/~peterlevi/variety/trunk/view/head:/data/scripts/set_wallpaper – simotek Mar 29 '15 at 04:15
  • @Andy false! a script built on that assumption will fail. you have to be able to detect KDE to properly call `konsole` instead of `gnome-terminal` for example – tatsu Mar 14 '19 at 08:44