#!/bin/sh

ROTTEXT=`xrandr -q | grep rotation | sed s/Current\ rotation\ .\ //g`
NEWROT=-1

if [ $ROTTEXT == "normal" ]; then
  NEWROT=1
  NEWPEN="NONE"
elif [ $ROTTEXT == "inverted" ]; then
  NEWROT=2
  NEWPEN="CCW"
elif [ $ROTTEXT == "left" ]; then
  NEWROT=3
  NEWPEN="CW"
elif [ $ROTTEXT == "right" ]; then
  NEWROT=0
  NEWPEN="NONE"
else
  xmessage "unhandled rotation"
  exit
fi

xrandr -o $NEWROT
RET=$?
if [ $RET == "1" ]; then
  xmessage -center "Sorry, your video driver does not support rotation!"
else
  xsetwacom set "Wacom Stylus" Rotate $NEWPEN
fi
