Shell script for clockwise rotation of display + Wacom input

2013-07-12

Tested and working under GNU/Linux with a ThinkPad X60t computer.

#!/bin/sh

# Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation.

rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o  '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')"

# Using current screen orientation proceed to rotate screen and input devices.

case "$rotation" in
    normal)
    # rotate to the left
    xrandr -o left
    xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate ccw
    xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate ccw
    xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate ccw
    xsetwacom set TPPS/2 IBM TrackPoint rotate cw
    ;;
    left)
    # rotate to inverted
    xrandr -o inverted
    xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate half
    xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate half
    xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate half
    xsetwacom set TPPS/2 IBM TrackPoint rotate half
    ;;
    inverted)
    # rotate to the right
    xrandr -o right
    xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate cw
    xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate cw
    xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate cw
    xsetwacom set TPPS/2 IBM TrackPoint rotate ccw
    ;;
    right)
    # rotate to normal
    xrandr -o normal
    xsetwacom set "Serial Wacom Tablet WACf008 stylus" Rotate none
    xsetwacom set "Serial Wacom Tablet WACf008 eraser" Rotate none
    xsetwacom set "Serial Wacom Tablet WACf008 touch" Rotate none
    xsetwacom set TPPS/2 IBM TrackPoint rotate none
    ;;
esac