summaryrefslogtreecommitdiff
path: root/ar/.local/bin/tablet
blob: 1b4e556bcdea53aeec0cddcc7402ce6f2c43b2a6 (plain)
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
#!/bin/sh

# Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation.
rotation="$(xrandr -q --verbose | grep 'connected' | grep -Eo '\) (normal|left|inverted|right) \(' | grep -Eo '(normal|left|inverted|right)')"
penstylus="$(xsetwacom list devices | grep 'Pen' | grep 'stylus' | sed 's/\s*id.*//g')"
penerase="$(xsetwacom list devices | grep 'Pen' | grep 'erase' | sed 's/\s*id.*//g')"
fingertouch="$(xsetwacom list devices | grep 'Finger' | grep 'touch' | sed 's/\s*id.*//g')"

# Using current screen orientation proceed to rotate screen and input tools.
case "$rotation" in
normal)
  # rotate to the left
  xrandr -o left
  xsetwacom set "$penstylus" rotate ccw
  xsetwacom set "$penerase" rotate ccw
  xsetwacom set "$fingertouch" rotate ccw
  ;;
left)
  # rotate to normal
  xrandr -o inverted
  xsetwacom set "$penstylus" rotate half
  xsetwacom set "$penerase" rotate half
  xsetwacom set "$fingertouch" rotate half
  ;;
inverted)
  # rotate to normal
  xrandr -o right
  xsetwacom set "$penstylus" rotate cw
  xsetwacom set "$penerase" rotate cw
  xsetwacom set "$fingertouch" rotate cw
  ;;
right)
  # rotate to normal
  xrandr -o normal
  xsetwacom set "$penstylus" rotate none
  xsetwacom set "$penerase" rotate none
  xsetwacom set "$fingertouch" rotate none
  ;;
esac