Ubuntu: How to determine which window manager is running



Question:

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?


Solution:1

If you have wmctrl installed, the first line of output from command

    wmctrl -m  

will show you the name of the window manager. If you don't have wmctrl installed, use the following command to install it:

    sudo apt-get install wmctrl  

Note, man wmctrl (that is, the man page for wmctrl) says in part:

-m Display information about the window manager ...

On my Ubuntu 11.10 / Linux 3.0.0-14-generic #23-Ubuntu x86_64 / metacity 2.34.1 system, the first line of output from wmctrl -m was: Name: Metacity
while echo $DESKTOP_SESSION showed ubuntu-2d and echo $XDG_CURRENT_DESKTOP showed Unity.

On a fresh Ubuntu 15.10 install of Ubuntu desktop software on an old laptop, the first line of output from wmctrl -m was: Name: Compiz
while the DESKTOP_SESSION and XDG_CURRENT_DESKTOP values were ubuntu and Unity


Solution:2

On Linux systems I tested environment variables XDG_CURRENT_DESKTOP and GDMSESSION and got the following results:


Ubuntu 16.04


Unity (7)

  • XDG_CURRENT_DESKTOP=Unity
  • GDMSESSION=ubuntu

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

Unity running without Mir

  • XDG_CURRENT_DESKTOP=Unity
  • GDMSESSION=ubuntu

XFCE

  • XDG_CURRENT_DESKTOP=XFCE
  • GDMSESSION=xfce

Ubuntu 12.04


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

Other Ubuntu based distributions


Mint 13 (Cinnamon)

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=cinnamon

Mint 16 (KDE edition)

  • XDG_CURRENT_DESKTOP=KDE
  • GDMSESSION=default

Mint 17 (Cinnamon)

  • XDG_CURRENT_DESKTOP=X-Cinnamon
  • GDMSESSION=default

Lubuntu 12.04

  • XDG_CURRENT_DESKTOP=LXDE
  • GDMSESSION=Lubuntu

Wasta 14.04

  • XDG_CURRENT_DESKTOP=X-Cinnamon
  • GDMSESSION=cinnamon

Wasta 14.04 using Gnome desktop.

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=gnome


Solution:3

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..


Solution:4

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}]  


Solution:5

xprop -id $(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}') -notype -f _NET_WM_NAME 8t   


Solution:6

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).


Solution:7

This is sort of possible with dbus and the Accounts Service (both by default in Ubuntu).

$ qdbus --system org.freedesktop.Accounts \                                                                  > /org/freedesktop/Accounts/User1000 \                                                                                       > org.freedesktop.Accounts.User.XSession                                                                                     ubuntu  

Worth noting that I've tested this with logging in through lightdm (that is the graphical login screen) , it did detect a classic desktop like blackbox , and obviously detects Unity. I suspect this is a value of what user selects on the login screen as session, that's why it's a bit easier to use that checking for processes


Solution:8

None of the above actually worked for me, I just wanted to know whether I had Gnome running as my current desktop session.

This is what worked, open a terminal

lsb_release -a  

(to check which flavor or version I had installed on my UBUNTU​ machine)

ls /usr/bin/*session  

(launches which desktop session/desktop environment currently in use)

gnome-shell --version   

(to find out which version of gnome is installed)


Solution:9

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"  


Solution:10

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.


Solution:11

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


Solution:12

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?!)


Solution:13

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.


Solution:14

This command is also good:

pgrep -l "gnome|kde|mate|cinnamon|lx|xfce|jwm"  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »