#!/bin/bash # based on http://liken.otsoa.net/pub/x41t/rotatetablet # modifications by JMR 2009-11-11 #STATUS_FILE=~/.rotate-status STATUS_FILE=/tmp/.rotate-status ######################## Keycodes PgUp/PgDown function keymap() { USER=`who |grep tty7 |awk -F" " '{print $1}'` if [ "$USER" ] then case "$1" in 3) echo 'Remapping buttons (right) ...' sudo setkeycodes 71 105 6f 106 6e 108 6d 103 ;; 1) echo 'Remapping buttons (left) ...' sudo setkeycodes 71 106 6f 105 6e 103 6d 108 ;; 2) echo 'Remapping buttons (inverted) ...' sudo setkeycodes 71 108 6f 103 6e 106 6d 105 ;; *) echo 'Remapping buttons (normal) ...' sudo setkeycodes 71 103 6f 108 6e 105 6d 106 ;; esac fi } ############################### function rotate() { case "$1" in 3|right) N=3; T=cw ; keymap 3 ;; 1|left) N=1; T=ccw ; keymap 1 ;; 2|inverted) N=2; T=half ; keymap 2 ;; 0|normal) N=0; T=none ; keymap 0 ;; *) echo -e "Usage:\n $(basename $0) [left|right|inverted|normal]\n\nIf no option is given, rotates the screen 90 degrees to the right.\n"; exit 1 ;; esac #xrandr -o $N & \ #More secure if [ "`/usr/bin/xrandr -o $N -v | grep -i 'randr' | wc -l`" -ne "1" ] then echo '!! Something went wrong...' export DISPLAY=":0.0" export XAUTHORITY=/var/lib/gdm/\:0.Xauth #/usr/bin/xset -display $DISPLAY dpms echo 'Trying to unrotate again...' /usr/bin/xrandr -o $N & fi xsetwacom set stylus Rotate $T & \ echo $N > $STATUS_FILE } if [ "$#" == "0" ]; then rotate $(((3+0$(cat $STATUS_FILE 2>/dev/null))%4)) else rotate $1 fi