#!/bin/sh
# init=/usr/bin/desk-compositor : start the compositor, then one native client.
# WLR_BACKENDS can be preset; default is wlroots' own autodetection (libseat + DRM + libinput).
. /usr/bin/desk-env
echo "desk-compositor: WLR_BACKENDS=${WLR_BACKENDS:-<auto>} LIBSEAT_BACKEND=$LIBSEAT_BACKEND"
/usr/bin/pomelo-compositor &
cpid=$!
i=0
while [ $i -lt 100 ] && [ ! -S "$XDG_RUNTIME_DIR/wayland-0" ] && kill -0 $cpid 2>/dev/null; do sleep 0.2; i=$((i+1)); done
if [ -S "$XDG_RUNTIME_DIR/wayland-0" ]; then
    echo "desk-compositor: socket is up, starting pomelo-calc"
    WAYLAND_DISPLAY=wayland-0 /usr/bin/pomelo-calc &
    kpid=$!
    sleep ${DESK_RUN_SECONDS:-15}
    echo "desk-compositor: compositor alive=$(kill -0 $cpid 2>/dev/null && echo yes || echo no) calc alive=$(kill -0 $kpid 2>/dev/null && echo yes || echo no)"
    kill $kpid 2>/dev/null; wait $kpid 2>/dev/null; echo "desk-compositor: pomelo-calc exit status $?"
    kill $cpid 2>/dev/null
fi
wait $cpid; echo "desk-compositor: pomelo-compositor exit status $?"
exit 0
