-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotate
executable file
·66 lines (63 loc) · 1.51 KB
/
rotate
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
59
60
61
62
63
64
65
#!/bin/bash
# Rotate the Microsoft Surface Pro touchscreen input
# Usage: rotate [clockwise|counter-clockwise|normal|inverted|left|right]
# The script will rotate the screen clockwise by default
matrix() {
declare -A dict=(
["normal"]="1 0 0 0 1 0 0 0 1"
["inverted"]="-1 0 1 0 -1 1 0 0 1"
["left"]="0 -1 1 1 0 0 0 0 1"
["right"]="0 1 0 -1 0 1 0 0 1"
)
echo "${dict["$1"]}"
}
rotate() {
M=$(matrix "$1")
PROP='Coordinate Transformation Matrix'
DEVICES=$(pointerID)
xrandr -o $1
for id in $DEVICES; do xinput set-prop $id "$PROP" $M; done;
notify-send \
"The system's display and touch-screen input have been rotated to $1" \
"Pointer device ID(s): $(echo $DEVICES | tr ' ' '\n' | sort -n | \
sed ':a;N;$!ba;s/\n/, /g')"
}
clockwise() {
declare -A dict=(
["normal"]="right"
["inverted"]="left"
["left"]="normal"
["right"]="inverted"
)
echo "${dict["$1"]}"
}
counterClockwise() {
declare -A dict=(
["normal"]="left"
["inverted"]="right"
["left"]="inverted"
["right"]="normal"
)
echo "${dict["$1"]}"
}
currentRotation() {
INFO="$(xrandr -q --verbose | grep LVDS1)"
if [ "$(echo $INFO | cut -d' ' -f 3)" = "primary" ];
then
echo "$(echo $INFO | cut -d' ' -f 6)"
else
echo "$(echo $INFO | cut -d' ' -f 5)"
fi
}
pointerID() {
echo "$(xinput --list | grep pointer | cut -f 2 | cut -d= -f 2)"
}
if [ "$1" = "" ] || [ "$1" = "clockwise" ];
then
rotate "$(clockwise "$(currentRotation)")"
elif [ "$1" = "counter-clockwise" ];
then
rotate "$(counterClockwise "$(currentRotation)")"
else
rotate "$1"
fi