Thanks; nice workaround! It worked for me on the CHUWI Hi10 X1 (N100) tablet running Linux Mint Mate. I just had to run:
xinput list
…to get the name of my touchscreen pointer (under “Virtual core pointer”), which was NYM TCA9537-B32 for me. (Replace GXTP7386:00 27C6:011A in the scripts with the name of your touchscreen pointer). Then I deleted the last line of both scripts because my tablet only had one device.
I combined both scripts into one, and bound it to the Pause/Break key in Keyboard Shortcuts, so it toggles between the two orientations:
#!/bin/bash
# File to store the current orientation
ORIENTATION_FILE="$(dirname "$0")/CurrentOrientation.txt"
# Default orientation if the file doesn't exist
if [ ! -f "$ORIENTATION_FILE" ]; then
echo "landscape" > "$ORIENTATION_FILE"
fi
# Read the current orientation
CURRENT_ORIENTATION=$(cat "$ORIENTATION_FILE")
if [ "$CURRENT_ORIENTATION" = "portrait" ]; then
# Switch to landscape
xrandr -o right
xinput set-prop "NYM TCA9537-B32" --type=float "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
echo "landscape" > "$ORIENTATION_FILE"
else
# Switch to portrait
xrandr -o normal
xinput set-prop "NYM TCA9537-B32" --type=float "Coordinate Transformation Matrix" 0 0 0 0 0 0 0 0 0
echo "portrait" > "$ORIENTATION_FILE"
fi
I also added lines like this to the end of /etc/sudoers to allow the script to run as sudo without needing a password, because it need to be run as sudo for me:
YOUR_USERNAME ALL=(ALL) NOPASSWD: /home/YOUR_USERNAME/Documents/Scripts/Orientation/ToggleScreenOrientation.sh
(where the path at the end is the full path to the script, without using ~/)