#!/bin/sh
#
# /usr/local/bin/localwebgalleryupdate
# Copyright 2009-2010 Jonas Smedegaard <dr@jones.dk>
#
# Autoconfigure Xorg to use all currently connected monitors
#

xinerama=1

lcd=
vga=
dvi=
tv=
for output in $(xrandr | egrep '^[^ ]+ connected' | awk '{print $1}'); do
	case $output in
	    LVDS|LVDS1|LVDS-1)
		    lcd="$output"
		;;
	    VGA|VGA1)
		    vga="$output"
		;;
	    TMDS-1|DVI1|DVI-I-1)
		    dvi="$output"
		;;
	    TV)
		    tv="$output"
		;;
	    *)
		echo "Unknown output \"$output\""
		;;
	esac
done

if [ -n "$lcd" ] && [ -n "$dvi" ]; then
	if [ -n "$xinerama" ]; then
		xrandr \
			--output "$lcd" --mode 1280x800 --rotate normal \
			--output "$dvi" --mode 1680x1050 --rotate normal --left-of $lcd --preferred
#		xrandr \
#			--output "$lcd" --mode 1280x800 --rotate left \
#			--output "$dvi" --mode 1680x1050 --rotate left --right-of $lcd
	else
		xrandr --output "$dvi" --mode 1280x800
	fi
elif [ -n "$vga" ]; then
	xrandr --output "$vga" --mode 1680x1050
else
	xrandr --auto
fi

## Mirrored screen, needs virtual screen min 1680x1050
#	xrandr --output TMDS-1 --mode 1680x1050
## Mirrored screen matching internal screen, needs virtual screen min 1280x800
#	xrandr --output TMDS-1 --mode 1280x800
## Xinerama horisontal (low-res), needs virtual screen min 1920x768
#	xrandr --output LVDS --mode 640x480
#	xrandr --output TMDS-1 --right-of LVDS --mode 1280x768
## Xinerama horisontal, needs virtual screen min 1680x1850
#	xrandr --output LVDS --mode 1280x800
#	xrandr --output TMDS-1 --above LVDS --mode 1680x1050
#else
#	xrandr --auto
#fi