#!/bin/sh

# This file asks for special X11 options to pass to server startup
# it returns the option string on stdout. All messages are printed to stderr,
# or the terminal.

# Currently it asks for the screen (monitor) to use, for use with XFree86 4.x

# Ask for startup screen (on laptop, we can select one of several displays)
timeout=10
if \ls -l /etc/X11/X | grep -q '/XFree86$' ; then # Running XFree4
	echo -e "Select one of the screens for X11 to use\n" 1>&2
	echo "1: External. The external screen (i.e. monitor) is forced." 1>&2
	echo "2: LCD. The internal LCD is forced." 1>&2
	echo "3: Both. Both screens (external and LCD) are turned on." 1>&2
	echo "4: Auto. The currently active screen becomes the X11 screen." 1>&2
	echo -e "\nAfter starting up the screen can be changed with the" 1>&2
	echo "special key combination of the laptop. However, the refresh" 1>&2
	echo "frequency is limited to the one of the initial setting." 1>&2
	echo -e "\nDefault is \"External\" (timeout $timeout seconds)." 1>&2
	until [ ! -z "$screen" ]; do
		echo "" 1>&2
		if read -n 1 -p "X11 startup screen: " -t $timeout sel; then
			case "$sel" in
				1 | "")
					screen=monitor
					;;
				2)
					screen=lcd
					;;
				3)
					screen=both
					;;
				4)
					screen=auto
					;;
				*)
					echo -e -n "\nInvalid value" 1>&2
					;;
			esac
		else
			screen=monitor
		fi
	done
	echo "" 1>&2
	
	X11OPTS="$X11OPTS -screen $screen"
fi

echo $X11OPTS
