nixos-configs/hypr/scripts/autorotate.sh

52 lines
1.2 KiB
Bash
Raw Normal View History

2023-06-24 06:35:40 -04:00
#!/usr/bin/env bash
# This script was forked from https://gitlab.com/snippets/1793649 by Fishonadish
SCREEN="eDP-1"
WAYLANDINPUT=("wacom-hid-52eb-finger"
"wacom-hid-52eb-pen")
2023-06-26 18:23:22 -04:00
2023-06-24 06:35:40 -04:00
function rotate_ms {
2023-06-26 18:23:22 -04:00
if [[ $(hyprctl activewindow | grep Waydroid) == "" ]]; then
case $1 in
"normal")
rotate 0
;;
"right-up")
rotate 3
;;
"bottom-up")
rotate 2
;;
"left-up")
rotate 1
;;
esac
elif [[ $(hyprctl monitors | grep "transform: 0") == "" ]]; then
rotate 0
fi
2023-06-24 06:35:40 -04:00
}
function rotate {
2023-06-26 18:23:22 -04:00
TARGET_ORIENTATION=$1
2023-06-24 06:35:40 -04:00
2023-06-26 18:23:22 -04:00
echo "Rotating to" $TARGET_ORIENTATION
2023-06-24 06:35:40 -04:00
2023-06-26 18:23:22 -04:00
hyprctl keyword monitor $SCREEN,transform,$TARGET_ORIENTATION
2023-06-24 06:35:40 -04:00
2023-06-26 18:23:22 -04:00
for i in "${WAYLANDINPUT[@]}"
do
hyprctl keyword device:"$i":transform $TARGET_ORIENTATION
done
2023-06-24 06:35:40 -04:00
2023-06-26 18:23:22 -04:00
/home/matt/.config/lisgd/config &
2023-06-24 06:35:40 -04:00
}
while IFS='$\n' read -r line; do
rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")"
[[ ! -z $rotation ]] && rotate_ms $rotation
done < <(stdbuf -oL monitor-sensor)