Toggle Between Normal and Inverted Orientation (toggle-inversion-only.sh)

#!/bin/sh

# This script is for X sessions. I don't know how this would
# work in wayland.

orientation="$(xrandr -q | grep -v dis | grep connected | awk '{print $5}' | sed 's:(::')"
displayName="$(xrandr -q | grep -v dis | grep connected | awk '{print $1}')"
normalMatrix="1 0 0 0 1 0 0 0 1"
invertedMatrix="-1 0 1 0 -1 1 0 0 1"

if [ "${orientation}" = "normal" ] ; then
	xrandr --output "${displayName}" --rotate inverted
	xinput set-prop "IPTS Touch" --type=float \
		"Coordinate Transformation Matrix" ${invertedMatrix}
	xinput set-prop "IPTS Stylus Pen (0)" --type=float \
		"Coordinate Transformation Matrix" ${invertedMatrix}
	xinput set-prop "IPTS Stylus Eraser (0)" --type=float \
		"Coordinate Transformation Matrix" ${invertedMatrix}
	xinput set-prop "Microsoft Surface Keyboard Mouse" --type=float \
		"Coordinate Transformation Matrix" ${invertedMatrix}
	xinput set-prop "Microsoft Surface Keyboard Touchpad" --type=float \
		"Coordinate Transformation Matrix" ${invertedMatrix}
else
	xrandr --output "${displayName}" --rotate normal
	xinput set-prop "IPTS Touch" --type=float \
		"Coordinate Transformation Matrix" ${normalMatrix}
	xinput set-prop "IPTS Stylus Pen (0)" --type=float \
		"Coordinate Transformation Matrix" ${normalMatrix}
	xinput set-prop "IPTS Stylus Eraser (0)" --type=float \
		"Coordinate Transformation Matrix" ${normalMatrix}
	xinput set-prop "Microsoft Surface Keyboard Mouse" --type=float \
		"Coordinate Transformation Matrix" ${normalMatrix}
	xinput set-prop "Microsoft Surface Keyboard Touchpad" --type=float \
		"Coordinate Transformation Matrix" ${normalMatrix}
fi
