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

37 lines
885 B
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
if [ "$#" -ne "1" ]; then
echo "usage: $0 ORIENTATION";
exit 1;
fi
ORIENTATION="$1"
# "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}\$" || {
echo "The given screen ${SCREEN} does not exist.";
exit 1;
}
xrandr --output "${SCREEN}" --rotate "${ORIENTATION}" || {
echo "Could not rotate ${SCREEN}!";
exit 1;
}
for i in "${DEVICES[@]}"; do
xinput --map-to-output "${i}" "${SCREEN}" || {
2021-06-17 16:59:44 +02:00
echo "Could not map device ${i} to screen ${SCREEN}! Please check output of 'xinput'.";
2021-06-17 16:25:38 +02:00
FAILURE=true
}
done
if [ "${FAILURE}" = "true" ]; then
# At least one error occurred.
exit 1;
fi