How to detect if Linux OS uses KDE or Gnome environment
Asked Answered
F

2

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?

Fortyfour answered 19/4, 2012 at 19:11 Comment(2)
I can't test this on my computer but try seeing what UIManager.getSystemLookAndFeelClassName() returns on either oneGodroon
Related: #3377179Juicy
S
11
System.getenv("XDG_CURRENT_DESKTOP")

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

See also

Sero answered 19/4, 2012 at 19:16 Comment(4)
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.Godroon
Tomaz, i will use the 'KDE_SESSION_VERSION' to check this. The problem is the KDE dont have a Desktop...Fortyfour
I'm forgot comment...System.getenv("XDG_CURRENT_DESKTOP") prints null for me in Linux Mint 12 with KDE native.Fortyfour
No, this is deprecated, don't use it. It's unset on Gnome3/Fedora16 also.Fitzwater
F
-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.

Fitzwater answered 19/4, 2012 at 21:39 Comment(4)
-1 This isn't an answer to the question and should have been a comment.Neoteric
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."Marilee
There are various places where people do care and should know, the first example is within xdg-utils cgit.freedesktop.org/xdg/xdg-utils/tree/scripts/… 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 bazaar.launchpad.net/~peterlevi/variety/trunk/view/head:/data/…Homogeny
@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 exampleMuldon

© 2022 - 2024 — McMap. All rights reserved.