#!/bin/bash

# Modified version of the script found at http://vminko.org/gentoo_on_x200

EXTERNAL_OUTPUT="VGA"
INTERNAL_OUTPUT="LVDS"
 
# Figure out which user and X11 display to work on
X_USER=$(who | grep " :0 " | awk '{print $1}')
export DISPLAY=':0.0'
 
# Switch to X user if necessary
if [ "$X_USER" != "$USER" ]
then
	SU="su $X_USER -c"
else
	SU="sh -c"
fi
 
# Figure out current state
EXTERNAL_STATE=$($SU xrandr | sed -n "/$EXTERNAL_OUTPUT/,/$INTERNAL_OUTPUT/p" | grep '*')
 
if [ -z "$EXTERNAL_STATE" ]
then
	$SU "xrandr --output $EXTERNAL_OUTPUT --auto"
	# disable internal display:
	$SU "xrandr --output $INTERNAL_OUTPUT --off"
else
	$SU "xrandr --output $INTERNAL_OUTPUT --auto"
	# disable external display:
	$SU "xrandr --output $EXTERNAL_OUTPUT --off"
fi

