36 lines
884 B
Plaintext
Raw Normal View History

2021-06-17 16:25:38 +02:00
#!/bin/bash
2021-06-17 16:37:04 +02:00
#
# Inspired by https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu
2021-06-17 16:25:38 +02:00
# 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"*)
2021-06-17 16:59:44 +02:00
ORIENTATION="right";
2021-06-17 16:25:38 +02:00
;;
*": left-up"*)
2021-06-17 16:59:44 +02:00
ORIENTATION="left";
2021-06-17 16:25:38 +02:00
;;
2021-06-17 16:52:12 +02:00
*": undefined"*)
2021-06-17 17:35:31 +02:00
echo "Reported orientation is 'undefined'. Please rotate the device a bit and try again." >&2;
2021-06-17 16:52:12 +02:00
exit 1;
;;
2021-06-17 16:25:38 +02:00
*)
2021-06-17 17:30:28 +02:00
echo "Could not parse ORIENTATION_STR: ${ORIENTATION_STR}" >&2;
2021-06-17 16:25:38 +02:00
exit 1;
esac
2021-06-17 17:20:23 +02:00
echo "${ORIENTATION}"