I want to detect which desktop manager I am running, and I found out that there are three environment variables, DESKTOP_SESSION
, XDG_SESSION_DESKTOP
, and XDG_CURRENT_DESKTOP
which could help me do so. But what exactly is the difference between these three variables? Thanks in advance.
2 Answers
Old question, but still highly ranked on Google, so worth answering in 2021.
You want to use only the official $XDG_CURRENT_DESKTOP
. Be careful that it is a colon-separated list (like $PATH
), so don't assume it only contains a single value (even if it does in most DEs). If you prefer to handle a single value, use $XDG_SESSION_DESKTOP
.
Official standards:
XDG_CURRENT_DESKTOP, defined in the Desktop Entry Specification since its version 1.2
XDG_SESSION_DESKTOP, best described in
systemd
's PAMDESKTOP_SESSION
is deprecated. Some DEs/WMs still set it for the sake of backward-compatibility, for new software it is not needed. It's 2021 after all.
For more details, including a bash function to parse and test a desktop environment, see https://unix.stackexchange.com/a/645761/4919
I'm not sure what the official reasons are for having many different variables, most likely different window & display managers all do their own particular configurations.
But all of them look the same, so using any one should work...
Here's what Mint's XFCE has:
$ echo $DESKTOP_SESSION
xfce
$ echo $XDG_SESSION_DESKTOP
xfce
$ echo $XDG_CURRENT_DESKTOP
XFCE
and also
$ echo $SESSION
xfce
$ echo $MDMSESSION
xfce
$ echo $GDMSESSION
xfce
Or (from env
):
XDG_MENU_PREFIX=xfce-
UPSTART_JOB=startxfce4
Your best bet (if you've got wmctrl
) may be this combined with grep/cut:
$ wmctrl -m
Name: Xfwm4
Class: xfwm4
PID: 5449
Window manager's "showing the desktop" mode: N/A
You can also be using a different Window Manager and Display Manager, and some different distributions store data in different places, so confusion reigns supreme. See these very related Q's: