Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there any way (such as a command or environmental variable) to determine what window manager is the one actively running in the current session?

share|improve this question
add comment

11 Answers 11

First, install wmctrl: sudo apt-get install wmctrl if you haven't installed it already. Then, run wmctrl -m.

man wmctrl says in part,

-m  Display information about the window manager ...

and on my Ubuntu 11.10 / Linux 3.0.0-14-generic #23-Ubuntu x86_64 / metacity 2.34.1 system, wmctrl -m shows (in part):

Name: Metacity

On the same system, echo $DESKTOP_SESSION shows ubuntu-2d and echo $XDG_CURRENT_DESKTOP shows Unity.

share|improve this answer
1  
So much easier than the other "guess and check" answers –  ean5533 Dec 25 '12 at 0:40
1  
This is the Right answer. –  bukzor Nov 26 '13 at 0:11
    
IMO, this is the correct answer to the question even though it needs installing of wmctrl which isn't present by default. –  user25656 Nov 29 '13 at 7:07
    
@vasa1, thanks for the edit –  jwpat7 Nov 29 '13 at 16:02
    
Unfortunately this doesn't work over ssh even if X11 is enabled. –  Sridhar-Sarnobat Apr 22 at 4:54
add comment

In the terminal type env to see all environment variables. Some of them are:

XDG_CURRENT_DESKTOP - Tells you what Windows Manager you are using

GDMSESSION - Tells you what option you selected from the lightdm greeter to login.

To use them, go to the terminal and type:

echo $XDG_CURRENT_DESKTOP

(Will output for example 'unity' if you are using Unity)

or

echo $GDMSESSION  

(Will output for example 'ubuntu' if you selected ubuntu in the login or 'ubuntu-2d' if you selected that one in the login.)

You have others if you look closer at the output of env like DESKTOP_SESSION and COMPIZ_CONFIG_PROFILE

Since what you are looking for is the name of what Window Manager is in usem the only way I see how to get this is by looking in the process list. To do this there is a command called pgrep ( Wikipedia ). I did the following to get the name since the parameter -l adds the process ID:

pgrep -l compiz |cut -d " " -f2 since the process is running by the same user there is no need to prefix the sudo part. You can then use this to create a script that does an action based on the Window Manager.

To look for other types, just change the word compiz to another like mutter, kwin, etc..

share|improve this answer
1  
Those just tell me the session name and desktop environment. Example it says "GNOME" which is a desktop environment that can use Metacity, Mutter, Compiz or other window managers. It says "gnome-classic" which is a session name, there is no such window manager with that name. –  Anonymous Oct 26 '11 at 23:04
1  
There you go. Found a command that can help with the process list. pgrep. Got to that part, at least it shows you the name of the window manager if found. Trying to check if I can add all of them together there. Your question is very good since Ubuntu 11.10 confuses a bit by using Compiz (Or mutter if when Gnome 3.x) so would be nice to point out the actual Window Manager that is used in Unity. –  Luis Alvarado Oct 27 '11 at 0:11
add comment

On Ubuntu 12.04 I tested environment variables XDG_CURRENT_DESKTOP and GDMSESSION and got the following results:

KDE

  • XDG_CURRENT_DESKTOP=
  • GDMSESSION=kde-plasma

Unity 3d

  • XDG_CURRENT_DESKTOP=Unity
  • GDMSESSION=ubuntu

Unity 2d

  • XDG_CURRENT_DESKTOP=Unity
  • GDMSESSION=ubuntu-2d

Gnome

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=gnome-shell

Gnome Classic

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=gnome-classic

Gnome Classic no effects

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=gnome-fallback

Ubuntu 14.04:

Unity running with Mir

  • XDG_CURRENT_DESKTOP=Unity
  • GDMSESSION=ubuntu

Note MIR_SERVER_NAME is also set

  • MIR_SERVER_NAME=session-$NUMBER

XFCE

  • XDG_CURRENT_DESKTOP=XFCE
  • GDMSESSION=xfce

Other Ubuntu based distributions:

Mint 13 (Cinnamon)

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=cinnamon

Mint 16 (KDE edition)

  • XDG_CURRENT_DESKTOP=KDE
  • GDMSESSION=default

Lubuntu 12.04

  • XDG_CURRENT_DESKTOP=LXDE
  • GDMSESSION=Lubuntu
share|improve this answer
7  
+1 because that's a lot of testing. –  Luis Alvarado Dec 10 '12 at 21:02
2  
Mint 13 (Cinnamon): XDG_CURRENT_DESKTOP=GNOME, GDMSESSION=cinnamon –  rik.shaw Dec 11 '12 at 18:02
1  
Lubuntu 12.04: XDG_CURRENT_DESKTOP=LXDE, GDMSESSION=Lubuntu –  rik.shaw Dec 11 '12 at 18:07
    
What about $DESKTOP_SESSION ? As a backup solution :) –  medigeek Jan 2 '13 at 10:25
    
What if I don’t use GDM? –  Robert Siemer Mar 13 at 11:20
add comment

I found pstree to be a big help. I believe you have to install it with sudo apt-get install pstree. This is what I got.

 ├─lightdm─┬─Xorg───2*[{Xorg}]
 │         ├─lightdm─┬─gnome-session─┬─bluetooth-apple───2*[{bluetooth-apple}]
 │         │         │               ├─compiz─┬─sh───gtk-window-deco───2*[{gtk-window-deco}]
 │         │         │               │        └─5*[{compiz}]
 │         │         │               ├─deja-dup-monito───2*[{deja-dup-monito}]
 │         │         │               ├─gnome-fallback-───2*[{gnome-fallback-}]
 │         │         │               ├─gnome-screensav───2*[{gnome-screensav}]
 │         │         │               ├─gnome-settings-───2*[{gnome-settings-}]
 │         │         │               ├─nautilus───2*[{nautilus}]
 │         │         │               ├─nm-applet───2*[{nm-applet}]
 │         │         │               ├─polkit-gnome-au───2*[{polkit-gnome-au}]
 │         │         │               ├─ssh-agent
 │         │         │               ├─telepathy-indic───2*[{telepathy-indic}]
 │         │         │               ├─update-notifier───2*[{update-notifier}]
 │         │         │               ├─vino-server───2*[{vino-server}]
 │         │         │               ├─zeitgeist-datah───{zeitgeist-datah}
 │         │         │               └─3*[{gnome-session}]
 │         │         └─{lightdm}
 │         └─2*[{lightdm}]
share|improve this answer
add comment
xprop -id $(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}') -notype -f _NET_WM_NAME 8t 
share|improve this answer
    
Can you explain how this works? Also, I think you' re missing a ) at the end. –  Louis Matthijssen May 15 at 6:53
    
@LouisMatthijssen 1. xprop -root -notype displays all of the root window's properties (and omits types for easier parsing), the output is send to awk via pipe; 2. awk instruction $1=="_NET[blah]CK:"{print $5}' compares first column of each row of the input it got through the pipe with a given string and if it finds the match it runs the code in brackets which prints the fifth column from this row - just so happens (entirely by accident, I bet) to be the ID of the "_NET_SUPPORTING_WM_CHECK" atom; 3. this ID is then used again to get the properties of the Windows Manager with xprop -id –  Cyprian Guerra May 15 at 19:31
add comment

I've been testing also with KDE and my conclusion is:

a) Graphical way, with HardInfo: the answer is normally in "Operating System" > "Desktop Environment", but if not you can look to "Environment variables". HardInfo is ready with all the tested distros, except the one with KDE, but it can be easily and quickly installed (only 2 packages in Linux Mint 13).

b) Command line, with this command: ps -A | egrep -i "gnome|kde|mate|cinnamon|lx|xfce|jwm". The item that appears in more lines should be the answer (if there is a draw the item with "session" should be the solution).

share|improve this answer
    
This is the only solution that worked for me. –  Sridhar-Sarnobat Apr 22 at 4:57
add comment

The following script resulted as the best answer to a similar question I posted over at unix.se. It also works great with Unity and LXDE.

if [ "$XDG_CURRENT_DESKTOP" = '' ]
then
  desktop=$(echo "$XDG_DATA_DIRS" | sed 's/.*\(xfce\|kde\|gnome\).*/\1/')
else
  desktop=$XDG_CURRENT_DESKTOP
fi

desktop=${desktop,,}  # convert to lower case
echo "$desktop"
share|improve this answer
add comment

I can only think of checking for known window managers in the running processes. There used to be a key in gconf that was set to the preferred window manager, but its deprecated since Gnome 2.12.

So, if this is for a programming purpose, I suggest you to research for all the linux window managers; some popular are:

  • gnome-shell*
  • compiz
  • metacity
  • mutter
  • sawfish

You would have to run a check for each with the command pgrep -l $WINDOW_MANAGER, where $WINDOW_MANAGER is the name of the window manager you want to check for. The pgrep command checks for running processes.

I am not 100% sure if Gnome Shell is considered a window manager; the rest of the window managers I got from a list in the /usr/bin/gnome-wm script. This script in fact should be usable (since its present on a clean install) but in my case it tries to run compiz which is not my default window manager (not in my Gnome session).

EDIT:

Well @Anarci 's comment seems to be more accurate. In my case it did show gnome-shell.

share|improve this answer
1  
Seems pgrep supports regex so a pattern with alternations can be used. pgrep -l "compiz|metacity|mutter|kwin|sawfish|fluxbox|openbox|xmonad" –  Anonymous Oct 26 '11 at 21:58
    
That's not enough: what if the user is running several X sessions with different managers? You should at least check that the window manger's operating on the display you're interested in (you can do that by examining $DISPLAY in its environment). –  Gilles Oct 26 '11 at 22:05
add comment

Here (MATE over Linux Mint) ...

echo $DESKTOP_SESSION ... returns ... default.desktop ---> Not valid

echo GDMSESSION ... returns ... GDMSESSION ---> Not valid

echo $XDG_CURRENT_DESKTOP ... returns ... (nothing) ---> Not valid

These 2 work for me:

A) You can run HardInfo. It's ready by default at least in Linux Mint; or you could install it (from Synaptic, ...).

You can run it a) from the main menu > Search box > hardinfo, or b) from the main menu > All applications > System Tools or Administration > System Information, or c) from the main menu > All applications > All > System Information, or d) from a terminal or console > hardinfo > Enter, or e) from the Run Application dialog (Alt+F2) > hardinfo > Enter.

Once HardInfo opens you just need to need to click on the "Operating System" item and look to the "Desktop Environment" line.

Nowadays, apart from GNOME and KDE, you could find MATE, Cinnamon, ...

B) In a terminal or console, run: pgrep -l "gnome|kde|mate|cinnamon" or ps -A | egrep -i "gnome|kde|mate|cinnamon" . The item that appears in more lines should be the answer

share|improve this answer
1  
echo GDMSESSION returns GDMSESSION is valid! You should enter echo $GDMSESSION instead –  Lucio Apr 14 '13 at 21:18
add comment

This command seems to be useful:

ls /usr/bin/\*session*

-> in GNOME returns /usr/bin/gnome-session (and more)

-> in MATE returns /usr/bin/mate-session (and more)

-> in LXDE returns /usr/bin/lxsession (and more)

-> in JWM returns /usr/bin/icewm-session (should be jwm-session, not?!)

share|improve this answer
2  
As others users had mentioned before, Desktop session != Window manager. So your answer in How can I find which desktop enviroment I am using? is not useful here.. –  Lucio Apr 15 '13 at 1:53
add comment

To know the version of the installed DE we can open Synaptic and put its name in the "Quick filter" box. Below "Installed Version" we have the answer. Next to it, below "Latest Version", we can see the highest to what we can update it to (at least if we have just clicked on "Reload" and considering only stable software -by default the access to the developing versions is usually disabled-). If instead of Synaptic the considered distro uses PackageKit or other a similar solution shoul be avaiable.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.