#!/bin/sh

COMPOSITOR="/usr/bin/rootston"
ROOTSTON_INI="/usr/share/phosh/rootston.ini"

gnome_session_args()
{
    ARGS="--disable-acceleration-check --session=phosh"

    # Use builtin session handling until we can rely
    # on a newer gnome-session everywhere
    if gnome-session --help | grep -qs -e--builtin; then
        ARGS="--builtin ${ARGS}"
    fi

    echo "${ARGS}"
}

if [ -x /usr/bin/phoc ]; then
  COMPOSITOR=/usr/bin/phoc
elif [ -x /usr/bin/phoc ]; then
  COMPOSITOR=/usr/bin/phoc
fi

if [ -f "/etc/phosh/rootston.ini" ]; then
  ROOTSTON_INI=/etc/phosh/rootston.ini
fi

# Run gnome-session through a login shell so it picks
# variables from /etc/profile.d (XDG_*)
[ -z "WLR_BACKENDS" ] || WLR_BACKENDS=drm,libinput
export WLR_BACKENDS
exec "${COMPOSITOR}" -C "${ROOTSTON_INI}" -E "bash -lc 'gnome-session $(gnome_session_args)'"
