arch/pkg/de-p1st-rotate/usr/lib/de-p1st-rotate/get-orientation

36 lines
884 B
Bash

#!/bin/bash
#
# Inspired by https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu
# Output of "monitor-sensor --accel | grep 'orientation'":
# === Has accelerometer (orientation: normal)
# Accelerometer orientation changed: right-up
# Feed output of 'monitor-sensor' and stop after first match of 'orientation'
ORIENTATION_STR="$(grep -m 1 'orientation' <( monitor-sensor ))" || exit $?
case "${ORIENTATION_STR}" in
*": normal"*)
ORIENTATION="normal";
;;
*": bottom-up"*)
ORIENTATION="inverted";
;;
*": right-up"*)
ORIENTATION="right";
;;
*": left-up"*)
ORIENTATION="left";
;;
*": undefined"*)
echo "Reported orientation is 'undefined'. Please rotate the device a bit and try again." >&2;
exit 1;
;;
*)
echo "Could not parse ORIENTATION_STR: ${ORIENTATION_STR}" >&2;
exit 1;
esac
echo "${ORIENTATION}"