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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#!/usr/bin/env bash
#
# rotate.sh: Rotates the screen by 90 degrees counterclockwise and/or
# gives the Wacom stylus input and/or TrackPoint the same orientation.
#
# Copyright (C) 2018 Eemeli Blåsten
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
#
# Usage: You can run this file with the command line option -s, -p or
# -t, or any combination, for example -sp, -ps, -tp, -tps. The
# behaviour is as follows.
#
# -s: Rotates the screen by 90 degrees. Depending on your desktop
# environment, the stylus input might get rotated or not.
#
# -p: Makes the stylus have the same rotation as the the screen.
#
# -t: Makes the trackpoint have the same rotation as the the screen.
#
# The script requires xrandr and xsetwacom.
rotScreen=0
rotPen=0
rotTP=0
while getopts ":spt" option; do
case $option in
s)
rotScreen=1
;;
p)
rotPen=1
;;
t)
rotTP=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# Find the display name. On some kernels it's LVDS1, on some others it's LVDS-1
display="$(xrandr | grep LVDS | sed 's/1.*/1/')"
# Find the line in "xrandr -q --verbose" output that contains current
# screen orientation and "strip" out current orientation.
getScreenOrientation() {
rotation="$(xrandr -q --verbose | grep "$display" | egrep -o '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')"
echo $rotation
}
# Find the device name from the STYLUS-entry in "xsetwacom list"
device="$(xsetwacom list | grep STYLUS | sed -E "s/( |\t)*id:.*//")"
# Function to set the stylus orientation to the same as the screen
setStylusToScreenOrientation() {
screenOrientation=$(getScreenOrientation)
case "$screenOrientation" in
normal)
# rotate to the normal
xsetwacom set "$device" rotate none
;;
left)
# rotate to left (counterclockwise)
xsetwacom set "$device" rotate ccw
;;
inverted)
# rotate to inverted
xsetwacom set "$device" rotate half
;;
right)
# rotate to right
xsetwacom set "$device" rotate cw
;;
esac
}
# Find the trackpoint device number
trackpointNbr="$(xinput list | grep TrackPoint | sed -E "s/^.*id=//" | sed -E "s/( |\t).*$//")"
# Set the trackpoint rotation to the same as the screen rotation
setTrackpointToScreenOrientation() {
screenOrientation=$(getScreenOrientation)
case "$screenOrientation" in
normal)
# rotate to the normal
xinput set-prop "$trackpointNbr" "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
;;
left)
# rotate to left (counterclockwise)
xinput set-prop "$trackpointNbr" "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
;;
inverted)
# rotate to inverted
xinput set-prop "$trackpointNbr" "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
;;
right)
# rotate to right
xinput set-prop "$trackpointNbr" "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
;;
esac
}
# Rotate the screen 90 degrees counterclockwise
rotateScreen() {
screenOrientation=$(getScreenOrientation)
case "$screenOrientation" in
normal)
# rotate to left (counterclockwise)
xrandr --output "$display" --rotate left
;;
left)
# rotate to inverted
xrandr --output "$display" --rotate inverted
;;
inverted)
# rotate to right
xrandr --output "$display" --rotate right
;;
right)
# rotate to the normal orientation
xrandr --output "$display" --rotate normal
;;
esac
}
if (($rotScreen)); then
rotateScreen
fi
if (($rotPen)); then
setStylusToScreenOrientation
fi
if (($rotTP)); then
setTrackpointToScreenOrientation
fi
# Make sure the stylus acts on the internal display, not an external display
xsetwacom set "$device" MapToOutput "$display"
|