#!/bin/sh
#
#        Script: FIX
#         Title: Fix Netbook goofies
#
# Last Modified: 2026-04-09 13:34:25
#

# Need the touchscreen ID
eval `xinput | awk '
/GXTP7386:00 27C6:0113/ && /pointer/ {
    print $5
    exit
}
/ELAN Touchscreen   / {
    print $5
    exit
}
'`

[ "$id" = "" ] && echo "No ID" && exit 255

x="1 0 0 0 1 0 0 1"
arg="Coordinate Transformation Matrix"
tm_left=" 0 -1 1  1 0 0  0 0 1"
tm_right="0 1 0 -1 0 1  0 0 1"
tm_normal="1 0 0  0 1 0  0 0 1"
tm_inverted="-1 0 1  0 -1 1  0 0 1"

# Use grub setting to determine the coordinate matrix we need
rotate=`cat /etc/default/grub | awk ' /fbcon/ { x = index($0,"rotate:") ; print substr($0,x+7,1) }'`

case "$rotate" in
  1) tm="$tm_right" ;;
  3) tm="$tm_left" ;;
  *) echo "Unable to find rotate direction" ; exit 255 ;;
esac

cmd="xinput set-prop $id --type=float \"$arg\" $tm"
# echo "$cmd"
eval $cmd
