app_containers: Add Wayland handling
This commit is contained in:
parent
60e83e345d
commit
c3d5c58ce3
|
@ -8,6 +8,14 @@ die() {
|
||||||
[ -z "$CONTAINER_NAME" ] && die "\$CONTAINER_NAME not set"
|
[ -z "$CONTAINER_NAME" ] && die "\$CONTAINER_NAME not set"
|
||||||
[ -z "$DISPLAY" ] && die "\$DISPLAY not set (you must run the script in a desktop environment"
|
[ -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 <https://liolok.com/run-desktop-app-with-systemd-nspawn-container>
|
# From <https://liolok.com/run-desktop-app-with-systemd-nspawn-container>
|
||||||
if [[ -n $DBUS_SESSION_BUS_ADDRESS ]]; then # remove prefix
|
if [[ -n $DBUS_SESSION_BUS_ADDRESS ]]; then # remove prefix
|
||||||
host_bus=${DBUS_SESSION_BUS_ADDRESS#unix:path=}
|
host_bus=${DBUS_SESSION_BUS_ADDRESS#unix:path=}
|
||||||
|
@ -21,7 +29,7 @@ else # default guess
|
||||||
host_pulse=$XDG_RUNTIME_DIR/pulse
|
host_pulse=$XDG_RUNTIME_DIR/pulse
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Default username
|
# Default username (assume `user` always has the same uid as the host user)
|
||||||
run_as=user
|
run_as=user
|
||||||
homedir=/home/user
|
homedir=/home/user
|
||||||
if [ "$CONTAINER_RUN_AS_ROOT" = true ]; then
|
if [ "$CONTAINER_RUN_AS_ROOT" = true ]; then
|
||||||
|
@ -39,9 +47,15 @@ sudo systemd-nspawn -M $CONTAINER_NAME \
|
||||||
`# Input devices` \
|
`# Input devices` \
|
||||||
--bind-ro=/dev/input \
|
--bind-ro=/dev/input \
|
||||||
--property=DeviceAllow='char-input r' \
|
--property=DeviceAllow='char-input r' \
|
||||||
|
`# Xdg runtime` \
|
||||||
|
--bind=$container_xdg_runtime:/run/xdg \
|
||||||
|
--setenv=XDG_RUNTIME_DIR=/run/xdg \
|
||||||
`# Xorg / Xwayland` \
|
`# Xorg / Xwayland` \
|
||||||
--bind-ro=/tmp/.X11-unix \
|
--bind-ro=/tmp/.X11-unix \
|
||||||
--setenv=DISPLAY=$DISPLAY \
|
--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` \
|
`# PulseAudio` \
|
||||||
--bind-ro=$host_pulse:/run/host/pulse \
|
--bind-ro=$host_pulse:/run/host/pulse \
|
||||||
--setenv=PULSE_SERVER=unix:/run/host/pulse/native \
|
--setenv=PULSE_SERVER=unix:/run/host/pulse/native \
|
||||||
|
|
Loading…
Reference in a new issue