#!/bin/bash # This is a script that toggles rotation of the screen through xrandr, # and also toggles rotation of the stylus, eraser and cursor through xsetwacom query_screen() { xrandr --verbose -q | while read screen conn p _ _ orientation _; do [ "$conn" = connected -a "$p" = primary ] || continue echo "$screen $orientation" break done } screen_properties=$(query_screen) orientation=${screen_properties#* } screen_name=${screen_properties% *} xrandr_to_xsetwacom() { case "$1" in normal) echo none ;; right) echo cw ;; inverted) echo half ;; left) echo ccw ;; esac } set_rotation() { local x="$(xrandr_to_xsetwacom "$1")" xrandr --output "${screen_name}" --rotate "$1" xsetwacom set 14 Rotate "$x" xsetwacom set 15 Rotate "$x" xsetwacom set 16 Rotate "$x" } flip() { case "$orientation" in normal) set_rotation inverted ;; right) set_rotation left ;; inverted) set_rotation normal ;; left) set_rotation right ;; esac } rotate_right() { case "$orientation" in normal) set_rotation right ;; right) set_rotation inverted ;; inverted) set_rotation left ;; left) set_rotation normal ;; esac } if [ $# = 0 ]; then flip exit elif [ "$1" = rotate ]; then rotate_right elif [ "$(xrandr_to_xsetwacom "$1")" ]; then set_rotation "$1" else exec >&2 echo "Usage: $0 [normal|right|inverted|left]" echo echo " With arguments, set the screen orientation." echo " Without arguments, flip the screen orientation 180 degrees." fi