#!/bin/sh

DISPLAY_MAIN="DP1"
DISPLAY_USB="DVI-I-1-1"
TOUCH="eGalaxTouch Virtual Device for Single"

TOUCH_ID=""

if [ "$TOUCH" != "" ]; then
  TOUCH_ID=`xinput --list | grep "$TOUCH" | cut -d= -f2 | awk '{ print $1 }'`
fi

HAS_USB_DISPLAY=`xrandr | grep $DISPLAY_USB`

if [ "$HAS_USB_DISPLAY" != "" ]; then
  xrandr --output $DISPLAY_USB --off
fi

eCalib Cal

if [ "$HAS_USB_DISPLAY" != "" ]; then
  xrandr --output $DISPLAY_USB --auto
  xrandr --output $DISPLAY_MAIN --left-of $DISPLAY_USB

  if [ "$TOUCH_ID" != "" ]; then
    xinput map-to-output $TOUCH_ID $DISPLAY_MAIN
  fi
fi


