Skip to content

Instantly share code, notes, and snippets.

@etihwnad
Forked from sarmbruster/rotate.sh
Last active December 13, 2016 19:48
Show Gist options
  • Save etihwnad/686fa2ea170300eb78a6e42dd1060c49 to your computer and use it in GitHub Desktop.
Save etihwnad/686fa2ea170300eb78a6e42dd1060c49 to your computer and use it in GitHub Desktop.
script for Thinkpad X1 Yoga to rotate screen and input devices
#!/bin/sh
# screen and input device rotation for e.g. a Thinkpad X1 Yoga
# adopted from by the script from http://ubuntuforums.org/showthread.php?t=996830&p=6274392#post6274392
#
# Usage:
# ./rotate.sh
# will rotate both the screen and input device either to right or normal setting depending on previous state. Additionally:
# * in "right" layout, a on screen keyboard (onboard) is started or stopped in normal mode
# * the touchpad is switched off in "right" mode
#
# I've bound this script to a shortcut key for easily flipping back and forth settins
stylus=`xsetwacom --list devices | grep " stylus" | cut -f 1`
eraser=`xsetwacom --list devices | grep " eraser" | cut -f 1`
touch=`xsetwacom --list devices | grep " touch" | cut -f 1`
# Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation.
rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')"
# different on my system
touchpadid=15
# Using current screen orientation proceed to rotate screen and input tools.
case "$rotation" in
normal)
# rotate to the right
xrandr -o right
xsetwacom set "$stylus" rotate cw
xsetwacom set "$touch" rotate cw
xsetwacom set "$eraser" rotate cw
xinput set-prop $touchpadid "Device Enabled" 0 # touchpad off
onboard &
;;
right)
# rotate to normal
xrandr -o normal
xsetwacom set "$stylus" rotate none
xsetwacom set "$touch" rotate none
xsetwacom set "$eraser" rotate none
xinput set-prop $touchpadid "Device Enabled" 1 # touchpad on
killall onboard
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment