summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autorotate.sh19
1 files 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