1. Introduction

Our Linux systems need a display server to operate the GUI windows that we use. While Xorg used to be the default for many years, it has not been maintained recently. Therefore, some open-source contributors started working on an alternative display server known as Wayland. However, the Linux world has not fully transitioned to Wayland yet.

We may be working with either Xorg or Wayland, and it’s useful to know which one we’re using. This will help us in debugging, whenever the need arises. In this tutorial, we’ll look at different methods to determine whether our Linux system is using Xorg or Wayland.

2. Checking XDG_SESSION_TYPE

The variable XDG_SESSION_TYPE stores the type of display server the system is using. Therefore, we can simply print the value of this variable on the shell to determine which display server we are running:

$ echo $XDG_SESSION_TYPE
x11

$ echo $XDG_SESSION_TYPE
wayland

From the output for both cases, we can see that the values for Xorg and Wayland will be “x11” and “wayland”, respectively.

3. Checking DESKTOP_SESSION

The variable DESKTOP_SESSION can give us information about the desktop environment the system is currently using, along with the display server:

$ echo $DESKTOP_SESSION
gnome-xorg

$ echo $DESKTOP_SESSION
gnome-wayland

In both cases above, we see that the first part of the output tells us the desktop environment our system is using, and the last part is the display server being used.

4. Checking WAYLAND_DISPLAY

We can check the WAYLAND_DISPLAY variable to determine whether our system is running Wayland:

$ echo $WAYLAND_DISPLAY
wayland-0

We see the output “wayland-0” in the case of Wayland. In the case of Xorg, there will be no output

5. Using the env Command With grep

The env command prints all the environment variables along with their values. We can pipe the output of this command into grep and search for “xorg” or “wayland”. Let’s see how this works:

$ env | grep -i xorg
XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome-xorg:/etc/xdg
MANDATORY_PATH=/usr/share/gconf/gnome-xorg.mandatory.path
DESKTOP_SESSION=gnome-xorg
XDG_SESSION_DESKTOP=gnome-xorg
DEFAULTS_PATH=/usr/share/gconf/gnome-xorg.default.path
XDG_DATA_DIRS=/usr/share/gnome-xorg:/usr/share/gnome:/home/karthik/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
GDMSESSION=gnome-xorg

$ env | grep -i wayland 
XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome-wayland:/etc/xdg
MANDATORY_PATH=/usr/share/gconf/gnome-wayland.mandatory.path
DESKTOP_SESSION=gnome-wayland
XDG_SESSION_DESKTOP=gnome-wayland
XDG_SESSION_TYPE=wayland
XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.NSGEX1
WAYLAND_DISPLAY=wayland-0 DEFAULTS_PATH=/usr/share/gconf/gnome-wayland.default.path
XDG_DATA_DIRS=/usr/share/gnome-wayland:/usr/share/gnome:/home/karthik/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
GDMSESSION=gnome-wayland

Above, we see the outputs for “xorg” and “wayland”, respectively. When we search for “xorg” on a Wayland system or “wayland” on an Xorg system, we’ll see a blank output. This way, we can determine whether the system runs Xorg or Wayland.

6. Conclusion

In this tutorial, we looked at different ways to determine which display server our system is using. The easiest way is the check the value of the variable XDG_SESSION_TYPE. We can use other methods to get additional data, such as the desktop environment being used.