-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrotate-touchscreen.sh
executable file
·58 lines (51 loc) · 2.29 KB
/
rotate-touchscreen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# https://gist.github.com/mildmojo/48e9025070a2ba40795c
if [ -z "$1" ] ; then
echo "Usage: $0 [normal|inverted|left|right]"
echo " "
exit 1
fi
function do_rotate
{
logger "rotate-touchscreen.sh: Changing rotation to $2"
# disable screen rotate, just want to rotate touchpad
# screen rotation already works in ubuntu
# xrandr --output $1 --rotate $2
TRANSFORM='Coordinate Transformation Matrix'
POINTERS=`xinput | grep 'slave pointer'`
POINTERS=`echo $POINTERS | sed s/↳\ /\$/g`
POINTERS=`echo $POINTERS | sed s/\ id=/\@/g`
POINTERS=`echo $POINTERS | sed s/\ \\\[slave\ pointer/\#/g`
iIndex=2
POINTER=`echo $POINTERS | cut -d "@" -f $iIndex | cut -d "#" -f 1`
while [ "$POINTER" != "" ] ; do
POINTER=`echo $POINTERS | cut -d "@" -f $iIndex | cut -d "#" -f 1`
POINTERNAME=`echo $POINTERS | cut -d "$" -f $iIndex | cut -d "@" -f 1`
#if [ "$POINTER" != "" ] && [[ $POINTERNAME = *"TouchPad"* ]]; then # ==> uncomment to transform only touchpads
#if [ "$POINTER" != "" ] && [[ $POINTERNAME = *"TrackPoint"* ]]; then # ==> uncomment to transform only trackpoints
#if [ "$POINTER" != "" ] && [[ $POINTERNAME = *"Digitizer"* ]]; then # ==> uncomment to transform only digitizers (touch)
#if [ "$POINTER" != "" ] && [[ $POINTERNAME = *"MOUSE"* ]]; then # ==> uncomment to transform only optical mice
if [ "$POINTER" != "" ] ; then # ==> uncomment to transform all pointer devices
case "$2" in
normal)
[ ! -z "$POINTER" ] && xinput set-prop "$POINTER" "$TRANSFORM" 1 0 0 0 1 0 0 0 1
;;
inverted)
[ ! -z "$POINTER" ] && xinput set-prop "$POINTER" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1
;;
left)
[ ! -z "$POINTER" ] && xinput set-prop "$POINTER" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1
;;
right)
[ ! -z "$POINTER" ] && xinput set-prop "$POINTER" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1
;;
esac
fi
iIndex=$[$iIndex+1]
done
}
XDISPLAY=`xrandr --current | grep primary | sed -e 's/ .*//g'`
if [ "$XDISPLAY" == "" ] || [ "$XDISPLAY" == " " ] ; then
XDISPLAY=`xrandr --current | grep connected | sed -e 's/ .*//g' | head -1`
fi
do_rotate $XDISPLAY $1