Poor documentation and confusing use cases can make it hard to learn about environment variables. If you hack on Wayland (whether as a shell developer, application developer or just curios user), these might be useful:
$WAYLAND_DISPLAY: This tells Wayland clients which Wayland compositor to connect to. If no Wayland display is set,
wayland-0 is the fallback. Most compositors will use
wayland-0 by default, or take the lowest available number if another compositor is already running on zero. Note that while the
wayland-[0-9] pattern is common, compositors can create their display with whatever name they like.
$XDG_RUNTIME_DIR: The directory where the Wayland display socket is created. Generally set to
/run/user/1000. You can see what displays are currently open with ls
$XDG_RUNTIME_DIR/wayland-* (assuming compositors are using the
lsof $XDG_RUNTIME_DIR/wayland-* will give you additional information, including showing which compositor is running on which display.
$DISPLAY: The environment variable used by X11 clients to select an X display. The X display sockets are located in
/tmp/.X11-unix/. Unlike Wayland clients, X clients don’t try a default display if the variable is unset.
$WAYLAND_DEBUG: If this environment variable is set to
1 it causes Wayland protocol messages to be dumped to stderr. Because this is implemented in libwayland, it works with basically all clients and all servers. If it is instead set to
server, it only shows messages coming from that type of connection. For normal apps
server will show nothing and
client will show all output. Servers can, however, use both the client and server library, and for that the filtering is useful. For example, a server may run as a client inside another Wayland compositor or it may connect to itself to provide a desktop background. In both cases it opens client connections you might want to filter out. This variable is useful for checking if a client is using Wayland, but reading the output raw is a PITA. If you’re trying to actually understand what’s going on, I suggest using the wayland-debug tool I built for that purpose.
$GDK_BACKEND: On Linux, can be
wayland. Wayland is used by default, but this can be changed by applications. note it’s GDK_BACKEND, not GTK_BACKEND (GDK is the subsystem of GTK that handles windowing).
$XDG_SESSION_TYPE: Can also be
wayland. Affects Qt and possibly other clients, but not GTK.
Feel free to leave any I missed in the comments below, as well as any tips and tricks you may have picked up.
EDIT: Running programs natively under Wayland from the Sway team may also be of interest