Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- if [ -z "$1" ]; then
- echo "Usage: $0 <display> [touchinput]"
- exit 1
- fi
- trap 'kill $(jobs -p)' SIGINT SIGTERM
- rotate() {
- if [ "$3" = "normal" ]; then
- swaymsg output "$1" transform 0
- show_keyboard=0
- elif [ "$3" = "left-up" ]; then
- swaymsg output "$1" transform 270
- elif [ "$3" = "right-up" ]; then
- swaymsg output "$1" transform 90
- elif [ "$3" = "bottom-up" ]; then
- swaymsg output "$1" transform 180
- else
- echo "Ignoring rotation: $3"
- continue
- fi
- if ! [ -z "$2" ]; then
- swaymsg input "$2" map_to_output "$1"
- fi
- }
- monitorer() {
- physrot=normal
- screenrot=normal
- rotatorpid=
- while read -r line; do
- line="${line#??}"
- physrot="$line"
- if [ -f ~/.rotation-lock ]; then
- if [ -n "$rotatorpid" ]; then
- kill "$rotatorpid"
- fi
- (inotifywait -e delete_self ~/.rotation-lock; rotate "$1" "$2" "$physrot") &
- rotatorpid=$!
- else
- rotate "$1" "$2" "$physrot"
- screenrot="$physrot"
- fi
- done
- }
- monitor-sensor \
- | grep --line-buffered "Accelerometer orientation changed" \
- | grep --line-buffered -o ": .*" \
- | monitorer "$1" "$2"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement