#!/bin/sh

export XKB_CONFIG_ROOT="$SNAP/usr/share/X11/xkb"

if [ -n "${WAYLAND_DISPLAY:-}" ]; then
    case "$WAYLAND_DISPLAY" in
        /*) wayland_socket="$WAYLAND_DISPLAY" ;;
        *)
            wayland_socket="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
            host_socket="${XDG_RUNTIME_DIR%/*}/$WAYLAND_DISPLAY"
            if [ ! -S "$wayland_socket" ] && [ -S "$host_socket" ]; then
                WAYLAND_DISPLAY="$host_socket"
                export WAYLAND_DISPLAY
                wayland_socket="$host_socket"
            fi
            ;;
    esac
    [ -S "$wayland_socket" ] || unset WAYLAND_DISPLAY
fi

exec "$@"
