268

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?

0

15 Answers 15

191

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

10
  • 5
    Unfortunately this doesn't work over ssh even if X11 is enabled. Apr 22, 2014 at 4:54
  • 2
    @Sridhar-Sarnobat on ubuntu 15.04, running ssh -Y {host} 'wmctrl -m' does return some values (e.g., "Name: Compiz", and several N/A's), but it makes sense that ssh would have limited info about the window manager.
    – michael
    May 4, 2015 at 2:52
  • on debian running cinnamon, this does not work. output of wmctrl -m is Name: Mutter(Muffin) while $XDG_CURRENT_DESKTOP=X-Cinnamon
    – Floyd
    Jan 2, 2016 at 8:58
  • On Xubuntu Wily, running Window Maker 0.95.6 - wmctrl reports N/A for all entries. GDMSESSION is set to wmaker-common but XDG_CURRENT_DESKTOP isnt set at all.
    – Mei
    Jul 11, 2016 at 19:13
  • 1
    Note to wanderers from outside Ubuntu. On RedHat wmctrl is available from the nux-dextop repo (see unix.stackexchange.com/questions/447999/…) Jun 5, 2018 at 14:33
152

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

You can use this line to get the output:

printf 'Desktop: %s\nSession: %s\n' "$XDG_CURRENT_DESKTOP" "$GDMSESSION"

Ubuntu 18.04 and 20.04 (Ubuntu on GNOME)

  • XDG_CURRENT_DESKTOP=ubuntu:GNOME
  • GDMSESSION=ubuntu

Ubuntu 18.04 (Ubuntu on Wayland)

  • XDG_CURRENT_DESKTOP=ubuntu:GNOME
  • GDMSESSION=ubuntu-wayland

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 / 18.04

  • XDG_CURRENT_DESKTOP=X-Cinnamon
  • GDMSESSION=cinnamon

Wasta 14.04 using Gnome desktop.

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=gnome

Ubuntu Mate 18.04

  • XDG_CURRENT_DESKTOP=MATE
  • GDMSESSION=mate

Xubuntu 18.04

  • XDG_CURRENT_DESKTOP=XFCE
  • GDMSESSION=xubuntu

Kali Linux kali-rolling 2020.2

  • XDG_CURRENT_DESKTOP=GNOME
  • GDMSESSION=lightdm-xsession
7
  • 4
    Mint 13 (Cinnamon): XDG_CURRENT_DESKTOP=GNOME, GDMSESSION=cinnamon
    – rik-shaw
    Dec 11, 2012 at 18:02
  • 1
    Lubuntu 12.04: XDG_CURRENT_DESKTOP=LXDE, GDMSESSION=Lubuntu
    – rik-shaw
    Dec 11, 2012 at 18:07
  • 2
    What about $DESKTOP_SESSION ? As a backup solution :) Jan 2, 2013 at 10:25
  • 1
    What if I don’t use GDM? Mar 13, 2014 at 11:20
  • 12
    And further it doesn’t answer what window manager I use! Mar 9, 2015 at 11:22
49

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

XDG_CURRENT_DESKTOP - Tells you what desktop environment 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 use, 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..

4
  • 4
    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, 2011 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. Oct 27, 2011 at 0:11
  • 1
    $XDG_CURRENT_DESKTOP is the current desktop environment, NOT the window manager.
    – Ken Sharp
    Feb 22, 2018 at 16:49
  • it seems that GDMSESSION returns the Window Manager - and of course $XDG_CURRENT_DESKTOP returns the Desktop Environment Nov 28, 2021 at 0:37
30

I found pstree to be a big help.

Installation

sudo apt-get install pstree

output

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}]
2
  • 2
    this got me there with my custom buildroot system.
    – jc__
    Feb 5, 2019 at 21:12
  • 2
    For me on Ubuntu 22.04, pstree came pre-installed. Dec 29, 2022 at 0:52
21
xprop -id $(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}') -notype -f _NET_WM_NAME 8t 
3
  • 3
    Can you explain how this works? Also, I think you' re missing a ) at the end. May 15, 2014 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
    – cprn
    May 15, 2014 at 19:31
  • Does not detect ratpoision but got me headed in the right direction
    – hildred
    Jan 30, 2021 at 19:31
15

Just two cents.

$ sudo apt install neofetch
$ neofetch

enter image description here

1
  • +1, neofetch is a nifty little tool, thank you! (well, not so little, but at least it works well). Dec 27, 2023 at 14:11
8
#! /bin/bash


windowManagerName () {
    local window=$(
        xprop -root -notype
    )

    local identifier=$(
        echo "${window}" |
        awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}'
    )

    local attributes=$(
        xprop -id "${identifier}" -notype -f _NET_WM_NAME 8t
    )

    local name=$(
        echo "${attributes}" |
        grep "_NET_WM_NAME = " |
        cut --delimiter=' ' --fields=3 |
        cut --delimiter='"' --fields=2
    )

    echo "${name}"
}


windowManagerName

Or in one line:

id=$(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}'); xprop -id "${id}" -notype -f _NET_WM_NAME 8t | grep "_NET_WM_NAME = " | cut --delimiter=' ' --fields=3 | cut --delimiter='"' --fields=2

1
  • 1
    this exactly answers the question! The only answer to the question I found. Jan 22, 2020 at 20:53
7

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" -wo | sort -u. The item that appears in more lines should be the answer (if there is a draw the item with "session" should be the solution). And it works through SSH.

2
  • XFCE also has several gnome-... processes (and a kde hit with kdevtmpfs)
    – Xen2050
    May 7, 2016 at 4:55
  • @Msedfi Does not work if the WM is lightdm.
    – SebMa
    May 26, 2023 at 14:23
3

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)

1
  • ls /usr/bin/*session showed me what was installed Jun 18, 2020 at 16:14
3

This question is 9 years old, but still topical. On my Ubuntu 20.04.2 LTS, I get :
wmctrl -m: GNOME Shell
inxi -Sxx: Desktop = Gnome 3.36.4; wm = gnome-shell; dm = GDM3 3.36.3
gnome-shell -- version: 3.36.4
env:GDM_SESSION : ubuntu ; DESKTOP_SESSION: ubuntu ; XDG_CURRENT_DESKTOP: ubuntu:GNOME
BUT
xprop... (from ruario): _NET_WM_NAME : GNOME Shell ; _GNOME_WM_KEYBINDINGS : Mutter, GNOME Shell ; _MUTTER_VERSION : 3.36.7
and neofetch: de = GNONE ; wm = Mutter
I deduce from this (but not very sure): GNOME is the desktop manager and GNOME Shell the window manager (Mutter must be a trace of my previous LTS versions 16.04 et 18.04).

1
  • That shows how confusing all the content and conclusions are in this entire thread. Your window manager is Mutter, as pointed out very helpfully and accurately by neofetch. (I get Mutter as well on a new install of 20.04, if that helps.)
    – Levente
    Mar 7, 2021 at 17:04
2

You can use tool called inxi. It can be obtained from Ubuntu Repositories by:

sudo apt install inxi

or from github : https://github.com/smxi/inxi

Just run the command as follows:

inxi -Sx
System:    Host: blackhole Kernel: 5.1.15-050115-lowlatency x86_64 bits: 64 compiler: gcc v: 8.3.0
           Desktop: i3 4.16.1-178-g31c0f1b8 Distro: Ubuntu 19.04 (Disco Dingo)

Note the Desktop: i3 part. In my case the window manager I use is i3.

Option -S displays system info and x adds info about window manager.

0

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

0
0

Script

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"
0

Desktop Environment lxqt (e.g. Lubuntu >= 18.10)

One way is open ~/.config/lxqt/session.conf and find

[General]
__userfile__=true
window_manager=openbox // <==
0

One solution that works through SSH :

$ cat /etc/X11/default-display-manager | xargs basename
lightdm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .