The context
Wayland has been specified with the assumption that clients and servers share the $XDG_RUNTIME_DIR
belonging to the user.
The way Wayland uses $XDG_RUNTIME_DIR
is for the server to place a file there that the client opens. This file could have any name, but by default it is wayland-0
(if that is in use it is wayland-1
etc.) or it can be specified by setting $WAYLAND_DISPLAY
.
This use of environment variables doesn’t map well to the world of snaps as the client and server run in different snaps environments each with its own $XDG_RUNTIME_DIR
. Specifically, $XDG_RUNTIME_DIR
is set to a subdirectory of the “normal” location for it named after the snap.
“Speed bumps”
Making this work for Wayland client snaps is a poor experience. There (at least) are four scenarios:
- A kiosk or signage solution with the server and client snaps running as daemons
- A “desktop” client snap with a non-snap server both running as a user
- A “desktop” client snap with a snapped server both running as a user
- A “desktop” non-snap client with a snapped server both running as a user
Most of the work I’ve done falls into the first scenario, so I’ll describe how that works in detail.
1. server and client snaps running as daemons
We have adopted the convention that the server simply changes its $XDG_RUNTIME_DIR
:
export XDG_RUNTIME_DIR=$(dirname $XDG_RUNTIME_DIR)
As it is running as a daemon this is actually /run/user/0
(which may not exist, so we create it). This works on Ubuntu Core (but currently only work on Ubuntu Classic by installing the server with --devmode
as it cannot create this directory).
The client snaps need to do a corresponding “dance”. Either by changing its $XDG_RUNTIME_DIR
or (recommended) by creating a link-file in its own $XDG_RUNTIME_DIR
:
ln $(dirname $XDG_RUNTIME_DIR)/wayland-0 $XDG_RUNTIME_DIR
(This oversimplifies as it omits error handling.)
The need to get this right complicates the story for creating a client snap. We want this to be as simple as possible.
2. client snap with a non-snap server both running as a user
Because of the way that $XDG_RUNTIME_DIR
is set, the same incantation should work (but the directory will be different - something like /run/user/1000
).
3. A client snap with a snapped server both running as a user
Again, the “dance” works.
4. A non-snap client with a snapped server both running as a user
Again, the “dance” works.
The problem
Having to repeat this “dance” in every server snap and every client snap is tedious and error prone. It seems something where the “developer story” could be improved.