Skip to content

Instantly share code, notes, and snippets.

@wonbinbk
Forked from Migacz85/autorotation.sh
Last active March 18, 2023 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonbinbk/92e6177ebb21220ec8291c733bd844e8 to your computer and use it in GitHub Desktop.
Save wonbinbk/92e6177ebb21220ec8291c733bd844e8 to your computer and use it in GitHub Desktop.
Script to monitor iio-sensor-proxy output and rotate the Thinkpad X1 Yoga display/touch mask/stylus mask based on that info.
#!/bin/bash
monitor-sensor --accel | while read line
orientation="normal"
rotate="none"
do
if [[ $line =~ .*right.* ]]; then
orientation="right"
rotate="cw"
elif [[ $line =~ .*left.* ]]; then
orientation="left"
rotate="ccw"
elif [[ $line =~ .*bottom.* ]]; then
orientation="inverted"
rotate="half"
elif [[ $line =~ .*normal.* ]]; then
orientation="normal"
rotate="none"
fi
# device Id 9 is the Touch screen
xsetwacom --set 9 Rotate ${rotate}
# devie Id 10 is the Stylus
xsetwacom --set 10 Rotate ${rotate}
# then the frame itself
xrandr -o ${orientation}
# better sleep a bit to not clog the CPU just for this
# Would be nice to actually poll for changes in the sensor device
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment