From 4a83f8650ca05a974ae10916e67022d0d6c66d1d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 30 Apr 2025 23:25:31 +0300 Subject: fix --- autorotate.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/autorotate.sh b/autorotate.sh index 4bf4074..0c9e58a 100644 --- a/autorotate.sh +++ b/autorotate.sh @@ -1,15 +1,18 @@ #!/bin/bash -declare -r SCREEN=eDP-1 +set -euf -o pipefail + declare -r WAYLANDINPUT=( '1118:2485:Microsoft_Surface_Keyboard_Touchpad' '1267:10780:ELAN9038:00_04F3:2A1C' ) +declare -r SCREEN=eDP-1 rotate_screen () { local -r orientation=$1 + echo "Rotating to $orientation" - swaymsg output $SCREEN transform $orientation + swaymsg output "$SCREEN" transform "$orientation" for input_device in "${WAYLANDINPUT[@]}"; do swaymsg input "$input_device" map_to_output "$SCREEN" @@ -25,7 +28,11 @@ process_orientation () { esac } -stdbuf -oL monitor-sensor | while IFS= read -r line; do - rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")" - [[ -n $rotation ]] && process_orientation $rotation -done +main () { + stdbuf -oL monitor-sensor | while IFS= read -r line; do + local rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")" + [[ -n $rotation ]] && process_orientation $rotation + done +} + +main -- cgit v1.2.3