Skip to content

Instantly share code, notes, and snippets.

@kamikat
Last active August 29, 2015 13:59
Show Gist options
  • Save kamikat/10749307 to your computer and use it in GitHub Desktop.
Save kamikat/10749307 to your computer and use it in GitHub Desktop.
Screen Rotation Script for Tablet PC (X220T)
#!/bin/bash
#
# Screen Rotation Script for Tablet PC (X220T)
#
# Usage:
# `rotator` - rotate screen clockwise to next orientation
# `rotator <orientation>` - rotate screen to orientation
# `<orientation>` can be
# xrandr style : normal,right,inverted,left
# xsetwacom style : none,cw,half,ccw
# plain number : 0,1,2,3
#
OUTPUT="LVDS1"
function screen_rotate () {
xrandr --output $OUTPUT --rotate $1
xsetwacom list devices | cut -f1 |
while read LINE
do
xsetwacom set "$LINE" rotate $2
done
}
function resolve_param () {
(
cat |
grep -A1 "| $1" |
cut --delimiter '|' --output-delimiter ' ' --fields 3,4 |
head -n2
) << EOF
| 0 | normal | none |
| 1 | right | cw |
| 2 | inverted | half |
| 3 | left | ccw |
| 0 | normal | none | rollback
EOF
}
function current_rotation () {
xrandr -q --verbose |
grep "$OUTPUT connected" |
sed -E 's@.*\) (normal|right|inverted|left) \(.*@\1@'
}
if [ "$1" != "" ]
then
PARAM=$(resolve_param $1 | head -n1)
else
PARAM=$(resolve_param `current_rotation` | tail -n1)
fi
if [ -z "$PARAM" ]
then
echo "Error: invalid rotation name"
exit
fi
screen_rotate $PARAM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment