#!/bin/bash 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" for input_device in "${WAYLANDINPUT[@]}"; do swaymsg input "$input_device" map_to_output "$SCREEN" done } process_orientation () { case $1 in "normal") rotate_screen 0 ;; "right-up") rotate_screen 90 ;; "bottom-up") rotate_screen 180 ;; "left-up") rotate_screen 270 ;; esac } 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