10c101c6485b9f3664def15b1822d8bc51e1891d
[profile/ivi/xorg-x11-server-misc.git] / i386-common / rotate.sh
1 #Variables
2 syntax_error=0
3 orientation=0
4
5 #Detect the current orientation
6 current_orientation="$(xrandr -q --verbose | grep 'connected' | egrep -o  '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')"
7 # 1=left, 2=inverted, 3=right, 0=normal
8
9 #Next orintation, rotate 90 degrees
10 case $current_orientation in
11         normal)
12                 orientation=3
13         ;;
14         left)
15                 orientation=0
16         ;;
17         inverted)
18                 orientation=1
19         ;;
20         right)
21                 orientation=2
22         ;;
23 esac
24
25 #Use the orientation if it is given
26 if [ "$1." != "." ]; then
27         orientation=$1
28 fi
29
30 #Touchscreen input method
31 method=evdev
32
33 #Detect input device id
34 device=`xinput --list | grep Cando|awk '{ print $12 }' | awk -F '=' '{ print $2 }'`
35
36 #Default input settings (first 2 rows of a 3x3 rotation matrix)
37 mata=1
38 matb=0
39 matc=0
40 matd=0
41 mate=1
42 matf=0
43
44 #Work out the input settng for each orientatiom
45 case $orientation in
46         0)
47                 mata=1
48                 matb=0
49                 matc=0
50                 matd=0
51                 mate=1
52                 matf=0
53         ;;
54         1)
55                 mata=0
56                 matb=-1
57                 matc=1
58                 matd=1
59                 mate=0
60                 matf=0
61         ;;
62         2 )
63                 mata=-1
64                 matb=0
65                 matc=1
66                 matd=0
67                 mate=-1
68                 matf=1
69         ;;
70         3 )
71                 mata=0
72                 matb=1
73                 matc=0
74                 matd=-1
75                 mate=0
76                 matf=1
77         ;;
78 esac
79
80 #Set the touchscreen rotation
81 if [ $method = "evdev" ]; then
82         xinput set-prop "$device" "Coordinate Transformation Matrix" $mata $matb $matc $matd $mate $matf 0 0 1
83 fi
84
85 #Set the screen rotation
86 xrandr -o $orientation
87