diff options
Diffstat (limited to 'dot/local/bin/thinkpad-rotate')
-rwxr-xr-x | dot/local/bin/thinkpad-rotate | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/dot/local/bin/thinkpad-rotate b/dot/local/bin/thinkpad-rotate new file mode 100755 index 0000000..db44030 --- /dev/null +++ b/dot/local/bin/thinkpad-rotate | |||
@@ -0,0 +1,70 @@ | |||
1 | #!/bin/bash | ||
2 | # This is a script that toggles rotation of the screen through xrandr, | ||
3 | # and also toggles rotation of the stylus, eraser and cursor through xsetwacom | ||
4 | |||
5 | query_screen() | ||
6 | { | ||
7 | xrandr --verbose -q | while read screen conn p _ _ orientation _; do | ||
8 | [ "$conn" = connected -a "$p" = primary ] || continue | ||
9 | echo "$screen $orientation" | ||
10 | break | ||
11 | done | ||
12 | } | ||
13 | |||
14 | screen_properties=$(query_screen) | ||
15 | orientation=${screen_properties#* } | ||
16 | screen_name=${screen_properties% *} | ||
17 | |||
18 | xrandr_to_xsetwacom() | ||
19 | { | ||
20 | case "$1" in | ||
21 | normal) echo none ;; | ||
22 | right) echo cw ;; | ||
23 | inverted) echo half ;; | ||
24 | left) echo ccw ;; | ||
25 | esac | ||
26 | } | ||
27 | |||
28 | set_rotation() | ||
29 | { | ||
30 | local x="$(xrandr_to_xsetwacom "$1")" | ||
31 | xrandr --output "${screen_name}" --rotate "$1" | ||
32 | xsetwacom set 14 Rotate "$x" | ||
33 | xsetwacom set 15 Rotate "$x" | ||
34 | xsetwacom set 16 Rotate "$x" | ||
35 | } | ||
36 | |||
37 | flip() | ||
38 | { | ||
39 | case "$orientation" in | ||
40 | normal) set_rotation inverted ;; | ||
41 | right) set_rotation left ;; | ||
42 | inverted) set_rotation normal ;; | ||
43 | left) set_rotation right ;; | ||
44 | esac | ||
45 | } | ||
46 | |||
47 | rotate_right() | ||
48 | { | ||
49 | case "$orientation" in | ||
50 | normal) set_rotation right ;; | ||
51 | right) set_rotation inverted ;; | ||
52 | inverted) set_rotation left ;; | ||
53 | left) set_rotation normal ;; | ||
54 | esac | ||
55 | } | ||
56 | |||
57 | if [ $# = 0 ]; then | ||
58 | flip | ||
59 | exit | ||
60 | elif [ "$1" = rotate ]; then | ||
61 | rotate_right | ||
62 | elif [ "$(xrandr_to_xsetwacom "$1")" ]; then | ||
63 | set_rotation "$1" | ||
64 | else | ||
65 | exec >&2 | ||
66 | echo "Usage: $0 [normal|right|inverted|left]" | ||
67 | echo | ||
68 | echo " With arguments, set the screen orientation." | ||
69 | echo " Without arguments, flip the screen orientation 180 degrees." | ||
70 | fi | ||