Skip to content

Instantly share code, notes, and snippets.

@matoken
Last active June 14, 2021 14:34
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 matoken/1c79ee3546e515e0fdb3bc1e55f9a87e to your computer and use it in GitHub Desktop.
Save matoken/1c79ee3546e515e0fdb3bc1e55f9a87e to your computer and use it in GitHub Desktop.
LENOVO Yoga260 auto screen rotate.
#!/bin/sh
MONITOR=$1
if [ -z $MONITOR ]; then
MONITOR="eDP-1"
fi
monitor-sensor \
| grep --line-buffered "Accelerometer orientation changed" \
| grep --line-buffered -o ": .*" \
| while read -r line; do
line="${line#??}"
if [ "$line" = "normal" ]; then
rotate=normal
matrix="0 0 0 0 0 0 0 0 0"
elif [ "$line" = "left-up" ]; then
rotate=left
matrix="0 -1 1 1 0 0 0 0 1"
elif [ "$line" = "right-up" ]; then
rotate=right
matrix="0 1 0 -1 0 1 0 0 1"
elif [ "$line" = "bottom-up" ]; then
rotate=inverted
matrix="-1 0 1 0 -1 1 0 0 1"
else
echo "Unknown rotation: $line"
continue
fi
xrandr --output "${MONITOR}" --rotate "$rotate"
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor Touchscreen pad" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor stylus" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor touch" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor Mouse" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor eraser" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor pad" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "ETPS/2 Elantech TrackPoint" --type=float "Coordinate Transformation Matrix" $matrix
xinput set-prop "ETPS/2 Elantech Touchpad" --type=float "Coordinate Transformation Matrix" $matrix
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment