arch/pkg/de-p1st-rotate/usr/bin/de-p1st-rotate-screen

48 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-06-17 16:25:38 +02:00
#!/bin/bash
# @post: $SCREEN variable and $DEVICES array are set
2021-06-17 16:52:12 +02:00
source /etc/de-p1st-rotate/config.cfg || exit $?
2021-06-17 16:25:38 +02:00
2021-06-17 17:20:23 +02:00
if [ "$#" -gt "1 " ] || [ "${1}" = "-h" ] || [ "${1}" = "--help" ] ; then
echo "usage:
- Manually specify orientation:
${0} ORIENTATION
- Automatically detect orientation:
2021-06-17 17:30:28 +02:00
${0}" >&2;
2021-06-17 16:25:38 +02:00
exit 1;
fi
2021-06-17 17:20:23 +02:00
if [ -z "${1}" ]; then
2021-06-17 17:30:28 +02:00
ORIENTATION="$(/usr/lib/de-p1st-rotate/get-orientation)" || {
echo "Could not get orientation: ${ORIENTATION}" >&2;
exit 1;
}
2021-06-17 17:20:23 +02:00
else
ORIENTATION="$1"
fi
2021-06-17 16:25:38 +02:00
# "xrandr ... || exit 1" does not work to check if $SCREEN exists.
# if e.g. the given output "$SCREEN" does not exist.
# Thus we check if $SCREEN is valid with grep:
xrandr --listmonitors | grep --quiet "\s${SCREEN}\$" || {
2021-06-17 17:30:28 +02:00
echo "The given screen ${SCREEN} does not exist." >&2;
2021-06-17 16:25:38 +02:00
exit 1;
}
xrandr --output "${SCREEN}" --rotate "${ORIENTATION}" || {
2021-06-17 17:30:28 +02:00
echo "Could not rotate ${SCREEN}!" >&2;
2021-06-17 16:25:38 +02:00
exit 1;
}
for i in "${DEVICES[@]}"; do
xinput --map-to-output "${i}" "${SCREEN}" || {
2021-06-17 17:30:28 +02:00
echo "Could not map device ${i} to screen ${SCREEN}! Please check output of 'xinput'." >&2;
2021-06-17 16:25:38 +02:00
FAILURE=true
}
done
if [ "${FAILURE}" = "true" ]; then
# At least one error occurred.
exit 1;
fi