I'm running Debian 12/Mate and I wanted to share this script for people who have two in one laptops because MATE (while awesome) doesn't have any screen flipping options (besides doing it manually). I suggest you put this script in your startup options.

#!/bin/bash

# Path to the accelerometer data
ACCELEROMETER_PATH="/sys/bus/iio/devices/iio:device0/in_accel_x_raw"

# Function to get current screen orientation
get_orientation() {
    xrandr --query | grep primary | awk '{print $4}'
}

# Function to rotate the screen
rotate_screen() {
    xrandr --output eDP-1 --rotate $1
}

# Function to adjust touchscreen input mapping
adjust_touchscreen_mapping() {
    device_name="$1"
    orientation="$2"
    case $orientation in
        normal)
            xinput --set-prop "$device_name" 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
            ;;
        inverted)
            xinput --set-prop "$device_name" 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
            ;;
    esac
}

# Default screen orientation
default_orientation="normal"

# Threshold for accelerometer reading
threshold=100

# Delay before applying screen rotation (in seconds)
rotation_delay=1.0

# Read initial accelerometer data to determine the initial orientation
read -r initial_accel_x < "$ACCELEROMETER_PATH"
if [ "$initial_accel_x" -gt 0 ]; then
    initial_orientation="inverted"
else
    initial_orientation="normal"
fi

# Rotate the screen based on the initial accelerometer data
if [ "$initial_orientation" != "$default_orientation" ]; then
    rotate_screen "$initial_orientation"
    adjust_touchscreen_mapping "SYNA7611:00 06CB:1952" "$initial_orientation"
fi

# Main loop
while true; do
    # Read accelerometer data
    read -r accel_x < "$ACCELEROMETER_PATH"

    # Determine orientation based on accelerometer data
    if [ "$accel_x" -gt 0 ]; then
        orientation="inverted"
    else
        orientation="normal"
    fi

    # Get current orientation
    current_orientation=$(get_orientation)

    # Rotate the screen if necessary with a delay
    if [ "$current_orientation" != "$orientation" ]; then
        sleep "$rotation_delay"
        rotate_screen "$orientation"
        adjust_touchscreen_mapping "SYNA7611:00 06CB:1952" "$orientation"
    fi

    # Sleep for a short duration before checking again
    sleep 1.0
done
Edit
Pub: 16 Mar 2024 22:38 UTC
Views: 50