#!/bin/sh
# configversion: 1

# This hook is called when the system reaches a off state (screen off)

case "$SXMO_WM" in
	dwm)
		# dmenu will grab input focus (i.e. power button) so kill it before going to
		# screenoff unless proximity lock is running (i.e. there's a phone call).
		sxmo_daemons.sh running proximity_lock -q || sxmo_dmenu.sh close
		;;
esac

# Start a periodic daemon (8s) "try to go to crust" after 8 seconds
# Start a periodic daemon (2s) blink after 5 seconds
# Resume tasks stop daemons
if [ -z "$SXMO_DISABLE_LEDS" ]; then
	sxmo_daemons.sh start idle_locker sxmo_idle.sh -w \
		timeout 8 'sxmo_daemons.sh start periodic_deeper sxmo_run_periodically.sh 8 sxmo_screenlock_deeper.sh --idle' \
		resume 'sxmo_daemons.sh stop periodic_deeper' \
		timeout 5 'sxmo_daemons.sh start periodic_blink sxmo_run_periodically.sh 2 sxmo_led.sh blink red blue' \
		resume 'sxmo_daemons.sh stop periodic_blink'
else
	sxmo_daemons.sh start idle_locker sxmo_idle.sh -w \
		timeout 8 'sxmo_daemons.sh start periodic_deeper sxmo_run_periodically.sh 8 sxmo_screenlock_deeper.sh --idle' \
		resume 'sxmo_daemons.sh stop periodic_deeper'
fi
