#!/bin/bash

#xrandr -o left

# normal
#xinput set-prop `xinput list | grep -i touch | grep -Po 'id=\K[0-9]+'` "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
# rotate left
#xinput set-prop `xinput list | grep -i touch | grep -v -e 'Keyboard' | grep -Po 'id=\K[0-9]+'` "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
# rotate right
#xinput set-prop `xinput list | grep -i touch | grep -Po 'id=\K[0-9]+'` "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
# reflection (invert)
#xinput set-prop `xinput list | grep -i touch | grep -Po 'id=\K[0-9]+'` "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1

exit

sleep 3

function getPortName() {
  len=$(expr index "$1" ' ')
  expr substr "$1" '1' "$(($len - 1))"
}

displayVerticalName='TouchPlanet XTM'
displayVerticalPortName=$(getPortName "$(xrandr | grep -E '1080x1920\+|2160x3840\+')")

echo verticalTouch: '"'$displayVerticalName'"' Port=$displayVerticalPortName

displayHorizontalName='pointer:UsbHID SingWon-CTP-V1.18B'
displayHorizontalPortName=$(getPortName "$(xrandr | grep '1080x1080+')")

echo horisontalTouch: '"'$displayHorizontalName'"' Port=$displayHorizontalPortName

xinput map-to-output "$displayVerticalName" "$displayVerticalPortName"
xinput map-to-output "$displayHorizontalName" "$displayHorizontalPortName"
