Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [ -z "$1" ]; then
  4. echo "Usage: $0 <display> [touchinput]"
  5. exit 1
  6. fi
  7.  
  8. trap 'kill $(jobs -p)' SIGINT SIGTERM
  9.  
  10. rotate() {
  11. if [ "$3" = "normal" ]; then
  12. swaymsg output "$1" transform 0
  13. show_keyboard=0
  14. elif [ "$3" = "left-up" ]; then
  15. swaymsg output "$1" transform 270
  16. elif [ "$3" = "right-up" ]; then
  17. swaymsg output "$1" transform 90
  18. elif [ "$3" = "bottom-up" ]; then
  19. swaymsg output "$1" transform 180
  20. else
  21. echo "Ignoring rotation: $3"
  22. continue
  23. fi
  24.  
  25. if ! [ -z "$2" ]; then
  26. swaymsg input "$2" map_to_output "$1"
  27. fi
  28. }
  29.  
  30. monitorer() {
  31. physrot=normal
  32. screenrot=normal
  33. rotatorpid=
  34.  
  35. while read -r line; do
  36. line="${line#??}"
  37. physrot="$line"
  38. if [ -f ~/.rotation-lock ]; then
  39. if [ -n "$rotatorpid" ]; then
  40. kill "$rotatorpid"
  41. fi
  42. (inotifywait -e delete_self ~/.rotation-lock; rotate "$1" "$2" "$physrot") &
  43. rotatorpid=$!
  44. else
  45. rotate "$1" "$2" "$physrot"
  46. screenrot="$physrot"
  47. fi
  48. done
  49. }
  50.  
  51. monitor-sensor \
  52. | grep --line-buffered "Accelerometer orientation changed" \
  53. | grep --line-buffered -o ": .*" \
  54. | monitorer "$1" "$2"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement