-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate-output.sh
executable file
·87 lines (81 loc) · 2.36 KB
/
rotate-output.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# Rotates the specified xrandr output in the relative direction specified.
# Since xrandr will only accept an absolute rotation value I need this for "flip" and "clockwise" rotation operations
output="$1"
new_rotation="$2"
if [ -z "$output" ] || [ -z "$new_rotation" ] ; then
echo "ERROR: Must specify an output and a rotation value"
echo "Usage: $0 OUTPUT normal|inverted|left|right|clockwise|flip"
echo
exit 1
fi
orig_rotation="$(xrandr --current --verbose | grep "$output connected " | egrep -o '\) (normal|left|inverted|right) \(')"
orig_rotation="${orig_rotation#) }"
orig_rotation="${orig_rotation% (}"
if [ -z "$orig_rotation" ] ; then
echo "ERROR: Output $output not found or not connected"
exit 1
fi
# The nested case statements seems inelegant, but it's probably the best way to do this
case "$new_rotation" in
clockwise)
case "$orig_rotation" in
normal)
desired_rotation="right"
;;
right)
desired_rotation="inverted"
;;
inverted)
desired_rotation="left"
;;
left)
desired_rotation="normal"
;;
esac
;;
flip)
case "$orig_rotation" in
normal)
desired_rotation="inverted"
;;
right)
desired_rotation="left"
;;
inverted)
desired_rotation="normal"
;;
left)
desired_rotation="right"
;;
esac
;;
counterclockwise)
case "$orig_rotation" in
normal)
desired_rotation="left"
;;
right)
desired_rotation="normal"
;;
inverted)
desired_rotation="right"
;;
left)
desired_rotation="inverted"
;;
esac
;;
normal|right|inverted|left)
desired_rotation="$1"
;;
*)
echo "ERROR: Unrecognised rotation value: $new_rotation"
echo "Usage: $0 OUTPUT normal|inverted|left|right|clockwise|flip"
echo
exit 1
;;
esac
echo "Setting rotate '$desired_rotation' on $output"
xrandr --output "$output" --rotate "$desired_rotation"