#!/bin/zsh # if we wanted to shift through all settings in xrandr order order=(normal left inverted right) # but if we just want to toggle between two: order=(normal right) xrandr_order=(normal left inverted right) old=$xrandr_order[1] if [ -e /dev/shm/rotation ] then old=`cat /dev/shm/rotation` fi function rotate() { # shift until we're at the current if its on the list z=(); while [ $#order > 0 -a $order[1] != $old ] do z=($z $order[1]); shift order; done # if not found, just reset the list # if [ $#order = 0 ] then order=($z) return fi order=($order $z) for ((x=0;x<$1;x++)) do t=$order[1]; shift order order=($order $t) done } function reorient() { orientation=$1 topx=0 topy=0 bottomx=9600 bottomy=7200 case $orientation in [0-3] ) reorient $xrandr_order[`expr $orientation + 1`] ;; normal ) wacom=0 ;; left ) wacom=2 tmp=$bottomy bottomy=$bottomx bottomx=$tmp ;; inverted ) wacom=3 ;; right ) wacom=1 tmp=$bottomy bottomy=$bottomx bottomx=$tmp ;; next ) rotate 1; reorient $order[1]; return ;; prev ) rotate `expr $#order - 1` reorient $order[1]; return ;; * ) return ;; esac if [ $old != $orientation ] then xrandr -o $orientation xsetwacom set stylus rotate $wacom if [ "$orientation" = "normal" ] then for i in stylus cursor eraser touch do xsetwacom set $i topx $topx xsetwacom set $i topy $topy xsetwacom set $i bottomx $bottomx xsetwacom set $i bottomy $bottomy done fi else print "orientation is $orientation\n"; fi echo $orientation > /dev/shm/rotation } reorient $1