From 1fdbd637984291339a33461dbf669e5275e4cd8b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 27 Jun 2018 00:54:19 -0400 Subject: thinkpad-rotate --- dot/local/bin/thinkpad-rotate | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 dot/local/bin/thinkpad-rotate (limited to 'dot/local') diff --git a/dot/local/bin/thinkpad-rotate b/dot/local/bin/thinkpad-rotate new file mode 100755 index 0000000..db44030 --- /dev/null +++ b/dot/local/bin/thinkpad-rotate @@ -0,0 +1,70 @@ +#!/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 -- cgit v1.2.3