Skip to content

Instantly share code, notes, and snippets.

@mothdotmonster
Created October 30, 2022 23:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mothdotmonster/6dd3fbd5b4247a6958274b456f9617ec to your computer and use it in GitHub Desktop.
Save mothdotmonster/6dd3fbd5b4247a6958274b456f9617ec to your computer and use it in GitHub Desktop.
spin your monitor around, slowly but surely
#!/bin/bash
# make sure we're not on Wayland, because xrandr doesn't work on Wayland
if [ "$(loginctl show-session $(loginctl user-status $USER | grep -E -m 1 'session-[0-9]+\.scope' | sed -E 's/^.*?session-([0-9]+)\.scope.*$/\1/') -p Type | grep -ic "wayland")" -ge 1 ]; then # stolen from stackoverflow
echo "You aren't using X!"
exit
fi
# no more annoying cursor
tput civis
# return back to normal when killed because you got bored
trap cleanup 1 2 3 6
cleanup() {
printf '\n%s\n' 'Putting display back to normal...'
sleep 1 # allow you to read the text it prints
xrandr --output "$o" --transform none # un-magic
tput cnorm # give cursor back
exit
}
# get primary display output name
o=$(xrandr | awk '/ primary / {print $1}')
# convert degrees to radians
dr () {
echo "$1 * 0.01745329" | bc -l
}
# do the funny
i=1
j=0
while true; do
xrandr --output "$o" --transform $(echo "c($(dr $i))" | bc -l),$(echo "-s($(dr $i))" | bc -l),0,$(echo "s($(dr $i))" | bc -l),$(echo "c($(dr $i))" | bc -l),0,0,0,1 # magic
printf '\033[2K%s\033[1m%s\033[m\n' "CURRENT ANGLE: " "$i°"
printf '\033[2K%s\033[1m%s\033[m\r\033[1A' "ROTATIONS SUFFERED: " "$j"
i=$((i+1))
if [ $i == 360 ]; then
j=$((j+1))
fi
i=$((i%360)) # don't fuck off to infinity
sleep 5 # give your screen some time to rest
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment