I want to check which Window Manager the user is using (like GNOME or KDE etc.). How do I do that?
Asked
Active
Viewed 1,534 times
3
-
2If you expand on "why" you want to detect it, someone might have a better idea. – viraptor Jul 26 '10 at 08:30
-
1possible duplicate of [Find the name of the X window manager](http://stackoverflow.com/questions/758648/find-the-name-of-the-x-window-manager) – Greg Hewgill Jul 26 '10 at 08:32
-
You might be able to check for specific processes which are usually running when user is using either of those windows managers. I haven't really checked this hence the comment instead of answer. – Maiku Mori Jul 26 '10 at 08:37
2 Answers
1
You can't. There is no central place where a program registers itself to say "hi, I'm the window manager".
For instance, I'm running xmonad. I simply start this by calling xmonad
in my ~/.xsession
file along with a couple of other programs to have it start when I login. You cannot really detect that.

Daniel Egeberg
- 8,359
- 31
- 44
-
I just thought of something, the Window Manager is just like any other program right? So it is in the processes list, for example, I'm running GNOME, and I got a process called 'gnome-sessions'. So I could check if that process is running so I know the user uses GNOME. You can't run 2 or more WM's at the same time anyhow right? – Jay Jul 26 '10 at 08:35
-
@Jay: Sure, if you have a list of all window managers, I suppose you could. There are a lot of different ones though. You cannot make a general solution. – Daniel Egeberg Jul 26 '10 at 08:38
-
1See `xnest` or `Xephyr` or `startx -- :1` for reasons why your assumption of "can't run 2 or more WM's at the same time" is incorrect. – sarnold Jul 26 '10 at 09:20
0
Since you're apparently using linux, you could use wmctrl -m or inxi -Sxx.
import subprocess
def get_wm():
output = subprocess.run(['wmctrl', '-m'], text=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if output.stderr:
return(output.stderr)
else:
return(output.stdout)
print(get_wm())

Honest Abe
- 8,430
- 4
- 49
- 64