#!/bin/sh

COMPOSITOR="/usr/bin/phoc"
PHOC_INI="/usr/share/phosh/phoc.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
fi

if [ -f /etc/phosh/phoc.ini ]; then
  PHOC_INI=/etc/phosh/phoc.ini
elif  [ -f /etc/phosh/rootston.ini ]; then
  # honor old configs
  PHOC_INI=/etc/phosh/rootston.ini
fi

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