aericktoes

X230 Tablet Rotation Script

Sep 28th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.39 KB | None | 0 0
  1. #!/bin/bash
  2. #Commented out lines aren't required on GNOME and some other DEs
  3.  
  4. state=$(cat /sys/devices/platform/thinkpad_acpi/hotkey_tablet_mode) #This file here is an indicator of whether it's in tablet mode or laptop mode
  5.  
  6. if mkdir /home/erik/.rot/.rot.sh.exclusivelock
  7. then
  8.     # Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation.
  9.     rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o  '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')"
  10.  
  11.     # Using current screen orientation proceed to rotate screen and input tools.
  12.     if [[ "$state" == "1" ]]
  13.     then
  14.         if [[ "$rotation" == "inverted" ]]
  15.         then
  16.             # rotate to the left
  17.             xrandr -o left
  18.             #xsetwacom --set "Wacom ISDv4 E6 Pen stylus" Rotate ccw
  19.             #xsetwacom --set "Wacom ISDv4 E6 Pen eraser" Rotate ccw
  20.             #xsetwacom --set "Wacom ISDv4 E6 Finger touch" Rotate ccw
  21.  
  22.             xsetwacom --set "Wacom ISDv4 E6 Pen stylus" ResetArea
  23.             xsetwacom --set "Wacom ISDv4 E6 Pen eraser" ResetArea
  24.             xsetwacom --set "Wacom ISDv4 E6 Finger touch" ResetArea
  25.         elif [[ "$rotation" == "left" ]]
  26.         then
  27.             # rotate to be inverted
  28.             xrandr -o inverted
  29.             #xsetwacom --set "Wacom ISDv4 E6 Pen stylus" Rotate half
  30.             #xsetwacom --set "Wacom ISDv4 E6 Pen eraser" Rotate half
  31.             #xsetwacom --set "Wacom ISDv4 E6 Finger touch" Rotate half
  32.             xsetwacom --set "Wacom ISDv4 E6 Pen stylus" ResetArea
  33.             xsetwacom --set "Wacom ISDv4 E6 Pen eraser" ResetArea
  34.             xsetwacom --set "Wacom ISDv4 E6 Finger touch" ResetArea
  35.         else
  36.             xrandr -o inverted
  37.             #xsetwacom --set "Wacom ISDv4 E6 Pen stylus" Rotate half
  38.             #xsetwacom --set "Wacom ISDv4 E6 Pen eraser" Rotate half
  39.             #xsetwacom --set "Wacom ISDv4 E6 Finger touch" Rotate half
  40.             xsetwacom --set "Wacom ISDv4 E6 Pen stylus" ResetArea
  41.             xsetwacom --set "Wacom ISDv4 E6 Pen eraser" ResetArea
  42.             xsetwacom --set "Wacom ISDv4 E6 Finger touch" ResetArea
  43.         fi
  44.     else
  45.         if [[ "$rotation" == "inverted" ]]
  46.         then
  47.             xrandr -o normal
  48.             #xsetwacom --set "Wacom ISDv4 E6 Pen stylus" Rotate none
  49.             #xsetwacom --set "Wacom ISDv4 E6 Pen eraser" Rotate none
  50.             #xsetwacom --set "Wacom ISDv4 E6 Finger touch" Rotate none
  51.             xsetwacom --set "Wacom ISDv4 E6 Pen stylus" ResetArea
  52.             xsetwacom --set "Wacom ISDv4 E6 Pen eraser" ResetArea
  53.             xsetwacom --set "Wacom ISDv4 E6 Finger touch" ResetArea
  54.         else
  55.             xrandr -o inverted
  56.             #xsetwacom --set "Wacom ISDv4 E6 Pen stylus" Rotate half
  57.             #xsetwacom --set "Wacom ISDv4 E6 Pen eraser" Rotate half
  58.             #xsetwacom --set "Wacom ISDv4 E6 Finger touch" Rotate half
  59.             xsetwacom --set "Wacom ISDv4 E6 Pen stylus" ResetArea
  60.             xsetwacom --set "Wacom ISDv4 E6 Pen eraser" ResetArea
  61.             xsetwacom --set "Wacom ISDv4 E6 Finger touch" ResetArea
  62.         fi
  63.     fi
  64.     sleep 1s
  65.     rmdir /home/erik/.rot/.rot.sh.exclusivelock
  66. fi
  67.  
  68. sleep 0.1s
  69. xsetwacom --set "Wacom ISDv4 E6 Pen stylus" ResetArea
  70. xsetwacom --set "Wacom ISDv4 E6 Pen eraser" ResetArea
  71. xsetwacom --set "Wacom ISDv4 E6 Finger touch" ResetArea
Advertisement
Add Comment
Please, Sign In to add comment