#!/usr/bin/env bash
set -euo pipefail

# ODesk owns the shell windows, while picom provides the compositor needed for
# opacity and transition effects. Keep the session usable on minimal systems
# by falling back to xcompmgr or opaque X11 surfaces.
if command -v picom >/dev/null 2>&1; then
	if ! pgrep -x picom >/dev/null 2>&1; then
		picom --daemon --backend "${ODESK_PICOM_BACKEND:-xrender}" \
			--vsync --no-fading-openclose >/dev/null 2>&1 || true
	fi
elif command -v xcompmgr >/dev/null 2>&1; then
	if ! pgrep -x xcompmgr >/dev/null 2>&1; then
		xcompmgr -n >/dev/null 2>&1 &
	fi
fi

exec /usr/bin/odesk "$@"
