You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.7KB

  1. #!/bin/bash
  2. path="/sys/bus/iio/devices/iio:device5" #Path is not fixed! So use workaround below, which is correct
  3. # path="/sys/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/*0483:91D1*/HID-SENSOR-200073.1.auto/iio:device?"
  4. margin1=800000
  5. margin2=400000
  6. current="none"
  7. accel_x=`find -L /sys/bus/iio/devices -maxdepth 2 -name in_accel_x_raw`
  8. accel_y=`find -L /sys/bus/iio/devices -maxdepth 2 -name in_accel_y_raw`
  9. accel_z=`find -L /sys/bus/iio/devices -maxdepth 2 -name in_accel_z_raw`
  10. HOST=`cat /etc/hostname`
  11. case "$HOST" in
  12. tablet|hnv-laptop)
  13. stylus="Wacom HID 4947 Pen stylus"
  14. touch="Wacom HID 4947 Finger touch"
  15. eraser="Wacom HID 4947 Pen eraser"
  16. ;;
  17. hegp-laptop)
  18. stylus="Wacom HID 48CA Pen stylus"
  19. touch="Wacom HID 48CA Finger touch"
  20. eraser="Wacom HID 48CA Pen eraser"
  21. ;;
  22. esac
  23. while true; do
  24. x=`cat $accel_x`
  25. y=`cat $accel_y`
  26. z=`cat $accel_z`
  27. oldcurrent=$current
  28. if [[ $x -gt "-$margin2" ]] && [[ $x -lt "$margin2" ]]; then
  29. if [[ "$y" -gt "$margin1" ]]; then
  30. if [[ $current != "half" ]]; then
  31. xrandr -o inverted
  32. xsetwacom set "$stylus" Rotate half
  33. xsetwacom set "$eraser" Rotate half
  34. xsetwacom set "$touch" Rotate half
  35. current="half"
  36. fi
  37. elif [[ "$y" -lt "-$margin2" ]]; then
  38. if [[ $current != "none" ]]; then
  39. xrandr -o normal
  40. xsetwacom set "$stylus" Rotate none
  41. xsetwacom set "$eraser" Rotate none
  42. xsetwacom set "$touch" Rotate none
  43. current="none"
  44. fi
  45. fi
  46. elif [[ "$x" -gt "$margin1" ]]; then
  47. if [[ $current != "ccw" ]]; then
  48. xrandr -o left
  49. xsetwacom set "$stylus" Rotate ccw
  50. xsetwacom set "$eraser" Rotate ccw
  51. xsetwacom set "$touch" Rotate ccw
  52. current="ccw"
  53. fi
  54. elif [[ "$x" -lt "-$margin1" ]]; then
  55. if [[ $current != "cw" ]]; then
  56. xrandr -o right
  57. xsetwacom set "$stylus" Rotate cw
  58. xsetwacom set "$eraser" Rotate cw
  59. xsetwacom set "$touch" Rotate cw
  60. current="cw"
  61. fi
  62. fi
  63. if [[ $oldcurrent != $current ]]; then
  64. if [[ $current == "cw" ]] || [[ $current == "ccw" ]]; then
  65. panel 1060 &
  66. hsetroot -tile /home/maxx/.config/bspwm/cat_vertical.png
  67. sleep 0.5
  68. retray 760 &
  69. else
  70. panel &
  71. hsetroot -tile /home/maxx/.config/bspwm/cat_sitting.png
  72. sleep 0.5
  73. retray &
  74. fi
  75. if [[ -z `pgrep picom` ]]; then
  76. picom --experimental-backends -b
  77. fi
  78. fi
  79. sleep 0.5
  80. done