]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | default_output=LVDS1 | |
4 | ||
5 | usage() { | |
6 | echo "Usage: | |
7 | rotate (left|right|invert) [output] | |
8 | rotate set (normal|right|inverted|left) [output] | |
9 | Examples: | |
10 | rotate left LVDS1 | |
11 | rotate set right HDMI2 | |
12 | ||
13 | Only the first letter of each command is checked (case-insensitive), so they | |
14 | can be abbreviated or even cut to one letter each in lower or upper case. | |
15 | ||
16 | For example, the following commands do the same thing: | |
17 | rotate set left | |
18 | rotate SET LeFt | |
19 | rotate s l | |
20 | rotate salad lasagna" | |
21 | } | |
22 | ||
23 | rot_to_num() { | |
24 | case $1 in | |
25 | # normal right invert left | |
26 | # convert to numbers to allow math to rotate | |
27 | [nN]*) rot0=0;; | |
28 | [rR]*) rot0=1;; | |
29 | [iI]*) rot0=2;; | |
30 | [lL]*) rot0=3;; | |
31 | *) usage; exit 2;; | |
32 | esac | |
33 | } | |
34 | num_to_rot() { | |
35 | case $1 in | |
36 | # maps to rot_to_num output | |
37 | 0) rot1=normal | |
38 | rot2=none;; | |
39 | 1) rot1=right | |
40 | rot2=cw;; | |
41 | 2) rot1=inverted | |
42 | rot2=half;; | |
43 | 3) rot1=left | |
44 | rot2=ccw;; | |
45 | esac | |
46 | } | |
47 | ||
48 | case $1 in | |
49 | [sS]*) | |
50 | # set: rotate set (normal|right|inverted|left) [output] | |
51 | output=${3:-$default_output} | |
52 | rot_to_num $2 | |
53 | ;; | |
54 | *) | |
55 | # rotate (left|right|invert) [output] | |
56 | output=${2:-$default_output} | |
57 | rot_to_num `xrandr --query --verbose | grep $output | awk '{print $5}'` | |
58 | case $1 in | |
59 | [lL]*) rot0=$(($rot0 - 1));; | |
60 | [rR]*) rot0=$(($rot0 + 1));; | |
61 | [iI]*) rot0=$(($rot0 + 2));; | |
62 | *) usage; exit 1;; | |
63 | esac | |
64 | ;; | |
65 | esac | |
66 | ||
67 | # add 4 modulo 4 to prevent negatives and overflows | |
68 | num_to_rot $((($rot0 + 4) % 4)) | |
69 | ||
70 | xrandr --output $output --rotation $rot1 | |
71 | # x220t | |
72 | if which xsetwacom >/dev/null; then | |
73 | xsetwacom --set stylus Rotate $rot2 | |
74 | xsetwacom --set eraser Rotate $rot2 | |
75 | xsetwacom --set touch Rotate $rot2 | |
76 | fi | |
77 | ||
78 | # reload bg | |
79 | ~/.fehbg |