Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!bash
- # This script rotates the screen and touchscreen input 90 degrees each time it is called,
- # also disables the touchpad, and enables the virtual keyboard accordingly
- # by Ruben Barkow: https://gist.github.com/rubo77/daa262e0229f6e398766
- #### configuration
- # find your Touchscreen and Touchpad device with `xinput`
- TouchscreenDevice='silead_ts'
- TouchpadDevice='SIPODEV USB Composite Device Mouse'
- # if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
- # echo 'Usage: rotate-screen.sh [OPTION]'
- # echo
- # echo 'This script rotates the screen and touchscreen input 90 degrees each time it is called,'
- # echo 'also disables the touchpad, and enables the virtual keyboard accordingly'
- # echo
- # echo Usage:
- # echo ' -h --help display this help'
- # echo ' -j (just horizontal) rotates the screen and touchscreen input only 180 degrees'
- # echo ' -n always rotates the screen back to normal'
- # exit 0
- # fi
- touchpadEnabled=$(xinput --list-props "$TouchpadDevice" | awk '/Device Enabled/{print $NF}')
- screenMatrix=$(xinput --list-props "$TouchscreenDevice" | awk '/Coordinate Transformation Matrix/{print $5$6$7$8$9$10$11$12$NF}')
- # Matrix for rotation
- # ⎡ 1 0 0 ⎤
- # ⎜ 0 1 0 ⎥
- # ⎣ 0 0 1 ⎦
- normal='1 0 0 0 1 0 0 0 1'
- normal_float='1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000'
- #⎡ -1 0 1 ⎤
- #⎜ 0 -1 1 ⎥
- #⎣ 0 0 1 ⎦
- inverted='-1 0 1 0 -1 1 0 0 1'
- inverted_float='-1.000000,0.000000,1.000000,0.000000,-1.000000,1.000000,0.000000,0.000000,1.000000'
- # 90° to the left
- # ⎡ 0 -1 1 ⎤
- # ⎜ 1 0 0 ⎥
- # ⎣ 0 0 1 ⎦
- left='0 -1 1 1 0 0 0 0 1'
- left_float='0.000000,-1.000000,1.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000'
- # 90° to the right
- #⎡ 0 1 0 ⎤
- #⎜ -1 0 1 ⎥
- #⎣ 0 0 1 ⎦
- right='0 1 0 -1 0 1 0 0 1'
- rotation_positions=([0]='normal' [1]='right' [2]='inverted' [3]='left')
- rotation_offset=3
- function rotate_touch_screen()
- {
- angle=$1
- index_for_angle=$((angle/90))
- xinput set-prop "$TouchscreenDevice" 'Coordinate Transformation Matrix' ${!rotation_positions[(rotation_offset+index_for_angle)%4]}
- }
- function do_rotate
- {
- TRANSFORM='Coordinate Transformation Matrix'
- # monitor-sensor \
- # | grep --line-buffered "Accelerometer orientation changed" \
- # | grep --line-buffered -o ": .*" \
- # | while read -r line; do
- monitor-sensor \
- | grep --line-buffered -o ": .*" \
- | while read -r line; do
- line="${line#??}"
- line="${line//)}"
- if [ "$line" = "normal" ]; then
- echo "Back to normal"
- xrandr -o normal
- rotate_touch_screen 0
- xinput enable "$TouchpadDevice"
- echo killall onboard
- elif [ "$line" = "left-up" ]; then
- echo "90° to the left"
- xrandr -o left
- rotate_touch_screen 270
- echo xinput disable "$TouchpadDevice"
- #killall onboard
- elif [ "$line" = "right-up" ]; then
- echo "90° to the right"
- xrandr -o right
- rotate_touch_screen 90
- echo xinput disable "$TouchpadDevice"
- #killall onboard
- elif [ "$line" = "bottom-up" ]; then
- echo "Upside down"
- xrandr -o inverted
- rotate_touch_screen 180
- echo xinput disable "$TouchpadDevice"
- # Remove hashtag below if you want pop-up the virtual keyboard
- onboard &
- else
- echo "Unknown rotation: $line"
- continue
- fi
- done
- }
- do_rotate
- k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement