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

45 lines
1.1 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:35:31 +02:00
ORIENTATION="$(/usr/lib/de-p1st-rotate/get-orientation)" || exit $?;
2021-06-17 17:20:23 +02:00
else
ORIENTATION="$1"
fi
2021-06-17 16:25:38 +02:00
2021-07-25 12:14:36 +02:00
# "xrandr ... || exit 1" does not work to check if $SCREEN exists,
# e.g. if the given output "$SCREEN" does not exist.
2021-06-17 16:25:38 +02:00
# 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