From c3d5c58ce30921e096c1044dc3b52b0b3c89fe3a Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sun, 25 Dec 2022 17:34:25 -0500 Subject: [PATCH] app_containers: Add Wayland handling --- app_containers/.local/bin/run_app_container | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app_containers/.local/bin/run_app_container b/app_containers/.local/bin/run_app_container index 88d94d3..2e5380f 100755 --- a/app_containers/.local/bin/run_app_container +++ b/app_containers/.local/bin/run_app_container @@ -8,6 +8,14 @@ die() { [ -z "$CONTAINER_NAME" ] && die "\$CONTAINER_NAME not set" [ -z "$DISPLAY" ] && die "\$DISPLAY not set (you must run the script in a desktop environment" +# Create a XDG_RUNTIME_DIR for guest on host +container_xdg_runtime="$(mktemp -d)" +trap 'rm -rf -- "$container_xdg_runtime"' EXIT + +# Link the current wayland session to the container's xdg runtime +# Note that the session itself must be bind-mounted first +ln -s /run/host/$WAYLAND_DISPLAY $container_xdg_runtime/$WAYLAND_DISPLAY + # From if [[ -n $DBUS_SESSION_BUS_ADDRESS ]]; then # remove prefix host_bus=${DBUS_SESSION_BUS_ADDRESS#unix:path=} @@ -21,7 +29,7 @@ else # default guess host_pulse=$XDG_RUNTIME_DIR/pulse fi -# Default username +# Default username (assume `user` always has the same uid as the host user) run_as=user homedir=/home/user if [ "$CONTAINER_RUN_AS_ROOT" = true ]; then @@ -39,9 +47,15 @@ sudo systemd-nspawn -M $CONTAINER_NAME \ `# Input devices` \ --bind-ro=/dev/input \ --property=DeviceAllow='char-input r' \ + `# Xdg runtime` \ + --bind=$container_xdg_runtime:/run/xdg \ + --setenv=XDG_RUNTIME_DIR=/run/xdg \ `# Xorg / Xwayland` \ --bind-ro=/tmp/.X11-unix \ --setenv=DISPLAY=$DISPLAY \ + `# Wayland (note the symlink created before in xdg runtime)` \ + --bind-ro=$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/run/host/$WAYLAND_DISPLAY \ + --setenv=WAYLAND_DISPLAY=$WAYLAND_DISPLAY \ `# PulseAudio` \ --bind-ro=$host_pulse:/run/host/pulse \ --setenv=PULSE_SERVER=unix:/run/host/pulse/native \