#!/usr/bin/execlineb -P
# gpm in foreground (-D). device/type from /etc/gpm.conf; optional Extra
# from s6-rc config (responsiveness, repeat_type, append, second mouse).

envfile -I /etc/gpm.conf
importas -uD "/dev/input/mice" device device
importas -uD "exps2" type type
envfile -I /etc/s6-rc/config/gpm.conf
importas -sCuD "-D" Args Args
importas -sCuD "" Extra Extra

# Brief wait for the mouse device (OpenRC start loop, max ~3s).
foreground {
	ifelse { test -e ${device} } { exit 0 }
	ifelse { test -e /dev/input/mice } { exit 0 }
	ifelse { test -e /dev/mouse } { exit 0 }
	foreground { sleep 1 }
	ifelse { test -e ${device} } { exit 0 }
	ifelse { test -e /dev/input/mice } { exit 0 }
	ifelse { test -e /dev/mouse } { exit 0 }
	foreground { sleep 1 }
	ifelse { test -e ${device} } { exit 0 }
	ifelse { test -e /dev/input/mice } { exit 0 }
	ifelse { test -e /dev/mouse } { exit 0 }
	exit 0
}

fdmove -c 2 1
exec /usr/sbin/gpm ${Args} -m ${device} -t ${type} ${Extra}
