From 7ff59553af4457cfc6666c187654b06981f3067e Mon Sep 17 00:00:00 2001 From: sphh Date: Tue, 18 May 2021 15:11:33 +0000 Subject: [PATCH 1/3] Correct a wrong check for the 'xrandr' executable. --- contrib/rotate-screen/rotate-screen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/rotate-screen/rotate-screen b/contrib/rotate-screen/rotate-screen index 1bc317712..62d38df4a 100755 --- a/contrib/rotate-screen/rotate-screen +++ b/contrib/rotate-screen/rotate-screen @@ -37,7 +37,7 @@ if test -z $XINPUT; then fi XRANDR=`which xrandr` -if test -z $GDBUS; then +if test -z $XRANDR; then echo "Command 'xrandr' not found." fi From 80f490ea713cc5a9e03f8da5a5a77a3147850fc3 Mon Sep 17 00:00:00 2001 From: sphh Date: Tue, 18 May 2021 18:24:01 +0000 Subject: [PATCH 2/3] Use modern "$()" instead of "``". --- contrib/rotate-screen/rotate-screen | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/contrib/rotate-screen/rotate-screen b/contrib/rotate-screen/rotate-screen index 62d38df4a..f139974f9 100755 --- a/contrib/rotate-screen/rotate-screen +++ b/contrib/rotate-screen/rotate-screen @@ -24,19 +24,19 @@ # # Check for commands needed -GDBUS=`which gdbus` +GDBUS=$(which gdbus) if test -z $GDBUS; then echo "Command 'gdbus' not found." exit 1 fi -XINPUT=`which xinput` +XINPUT=$(which xinput) if test -z $XINPUT; then echo "Command 'xinput' not found." exit 2 fi -XRANDR=`which xrandr` +XRANDR=$(which xrandr) if test -z $XRANDR; then echo "Command 'xrandr' not found." fi @@ -51,18 +51,18 @@ get_orientation () { DBUS="--system --dest net.hadess.SensorProxy --object-path /net/hadess/SensorProxy" # Check, if DBus is available - ORIENTATION=`$GDBUS call $DBUS \ + ORIENTATION=$($GDBUS call $DBUS \ --method org.freedesktop.DBus.Properties.Get \ - net.hadess.SensorProxy HasAccelerometer` + net.hadess.SensorProxy HasAccelerometer) if test "$ORIENTATION" != "(,)"; then echo "No sensor available!" exit 10 fi # Get the orientation from the DBus - ORIENTATION=`$GDBUS call $DBUS \ + ORIENTATION=$($GDBUS call $DBUS \ --method org.freedesktop.DBus.Properties.Get \ - net.hadess.SensorProxy AccelerometerOrientation` + net.hadess.SensorProxy AccelerometerOrientation) # Release the DBus $GDBUS call --system $DBUS --method net.hadess.SensorProxy.ReleaseAccelerometer > /dev/null @@ -129,14 +129,14 @@ do_rotate () { # Get the tablet's orientation -ORIENTATION=`get_orientation` +ORIENTATION=$(get_orientation) # Get all pointers -POINTERS=`$XINPUT | grep slave | grep pointer | sed -e 's/^.*id=\([[:digit:]]\+\).*$/\1/'` +POINTERS=$($XINPUT | grep slave | grep pointer | sed -e 's/^.*id=\([[:digit:]]\+\).*$/\1/') # Get the display and its orientation -XDISPLAY=`$XRANDR --current --verbose | grep primary | cut --delimiter=" " -f1` +XDISPLAY=$($XRANDR --current --verbose | grep primary | cut --delimiter=" " -f1) # Rotate the screen and pointers -echo "Rotate display $XDISPLAY to $ORIENTATION orientation (Pointers: `echo $POINTERS | sed 's/\n/ /g'`)" +echo "Rotate display $XDISPLAY to $ORIENTATION orientation (Pointers: $(echo $POINTERS | sed 's/\n/ /g'))" do_rotate $ORIENTATION $XDISPLAY $POINTERS From 9621155f9cefaf81d9ed0c353e2aad7a723a3156 Mon Sep 17 00:00:00 2001 From: sphh Date: Tue, 18 May 2021 18:27:37 +0000 Subject: [PATCH 3/3] Return error message and exit. --- contrib/rotate-screen/rotate-screen | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/rotate-screen/rotate-screen b/contrib/rotate-screen/rotate-screen index f139974f9..99584b44f 100755 --- a/contrib/rotate-screen/rotate-screen +++ b/contrib/rotate-screen/rotate-screen @@ -55,7 +55,8 @@ get_orientation () { --method org.freedesktop.DBus.Properties.Get \ net.hadess.SensorProxy HasAccelerometer) if test "$ORIENTATION" != "(,)"; then - echo "No sensor available!" + echo "No sensor available! " + echo "(Do you have the 'iio-sensor-proxy' package installed and enabled?)" exit 10 fi @@ -130,6 +131,11 @@ do_rotate () { # Get the tablet's orientation ORIENTATION=$(get_orientation) +ret=$? +if test $ret != 0; then + echo $ORIENTATION + exit $ret +fi # Get all pointers POINTERS=$($XINPUT | grep slave | grep pointer | sed -e 's/^.*id=\([[:digit:]]\+\).*$/\1/')