#!/usr/bin/env bash
# rotate-laptop -- rotate the screen and touchpad at the same time

. lib.bash || exit

dir=$1

case $dir in
    n|normal|u|up|default|reset)
	dir=normal;;
    l|left)
	dir='left';;
    r|right)
	dir='right';;
    i|inverted|d|down)
	dir='inverted';;
    '')
	die "missing direction";;
    *)
	die "bad direction '$dir'";;
esac

case $dir in
    normal)
	coords=( 1  0  0
		 0  1  0
		 0  0  1);;
    left)
	coords=( 0 -1  1
		 1  0  0
		 0  0  1);;
    right)
	coords=( 0  1  0
		-1  0  1
		 0  0  1);;
    inverted)
	coords=(-1  0  1
		 0 -1  1
		 0  0  1);;
esac

xrandr -o $dir

xinput set-prop "ETPS/2 Elantech Touchpad" \
	"Coordinate Transformation Matrix" \
	${coords[@]}
