#!/bin/bash

NUM_DEVICES=`/opt/bin/xrandr_devices | wc -l`
DEVICE_MAIN=`/opt/bin/xrandr_devices | head -1 | cut -f1 -d,`
DEVICE_USB=`/opt/bin/xrandr_devices | tail -1 | cut -f1 -d,`

if [ "$NUM_DEVICES" = "2" ]; then
  xrandr --output $DEVICE_USB --off
  sleep 1
fi

xinput_calibrator

if [ "$NUM_DEVICES" = "2" ]; then
  sleep 2
  xrandr --output $DEVICE_USB --auto
  sleep 2
  xrandr --output $DEVICE_USB --right-of $DEVICE_MAIN
  # the was needed by a pedro porto machine that had a external customer
  # screen that only worked when we clicked on it
  ps xa | grep graphical_display_v2 | grep -v grep | awk '{ print $1 }' | xargs kill -9
  sleep 5
  xdotool mousemove 2000 1 click 1
  sleep 1
  xdotool mousemove 50 50 click 1
fi

