# Automatically Fixing Auto-Rotate Screen Orientation on PostmarketOS Devices Running MATE DE

As I delve into my daily life with my trusty Samsung Galaxy Tab A (2015) running PostmarketOS, I've found myself facing a common issue that has been plaguing many users of this device. The tablet's ability to automatically rotate the screen based on its orientation is broken, forcing me to manually adjust it every time I reboot. In this article, we'll explore a simple yet effective solution to fix this problem using MATE Desktop environment and the power of scripting.

## A Reluctant e-Book Reader

For months now, my tablet has served as an excellent e-book reader, thanks to KOReader installed on its operating system. I've also experimented with phosh and plasma-mobile, but unfortunately, these environments came with a significant performance hit due to the device's outdated processor and limited RAM (2 GB). Thus, I settled for MATE Desktop environment, which has proven to be a more stable and responsive experience.

## A Second Screen Savior

Lately, my tablet has become an indispensable second screen for work. The device seamlessly integrates with my laptop, allowing me to multitask efficiently. However, the manual rotation of the screen every time I reboot is becoming increasingly frustrating. That's when I decided to dig into the PostmarketOS wiki and explore potential solutions.

## Testing the Auto-Rotate Sensor

The first step in our journey was to verify whether the auto-rotate sensor on my device actually works and if we can read values from it. We started by installing some basic necessary packages using the `device terminal`. Next, we ran the `sensor monitor-sensor` command to test its functionality.

As shown below, we're able to successfully read rotation values from the sensor as I rotate the tablet in different orientations:

```html

Sensor Values

```

## Crafting the Auto-Rotate Script

With the sensor's capabilities confirmed, our next task was to create a script that would change the screen orientation using `xrandr` according to the sensor value. We'll replace the name of your touch input device in the script, which can be obtained by running the command `xinput --list` on the device terminal.

Here's an example script (`auto-rotate-screen.sh`) that does just that:

```html #!/bin/bash

# Replace with your touchscreen device name (obtained using xinput --list) DEVICE_NAME="your_touchscreen_device"

if [ "$DEVICE_NAME" != "" ]; then

# Get the current rotation value from the sensor ROTATION_VALUE=$(sensor monitor-sensor | grep "orientation" | awk '{print $NF}')

case $ROTATION_VALUE in 90|270) echo "Rotate to landscape" xrandr --rotation landscape & ;; 180) echo "Rotate to portrait" xrandr --rotation portrait & ;; *) echo "Unsupported rotation value: $ROTATION_VALUE" >&2 exit 1 ;; esac fi ```

## Making the Script Executable

Once your script is ready, save it and make it executable using the `chmod +x auto-rotate-screen.sh` command.

## Testing the Script

We'll test our script in the terminal by running `./auto-rotate-screen.sh`. We can stop the script using Ctrl+C. If everything works as expected, we should see the screen orientation change according to the sensor value.

## Auto-Starting the Script

To ensure that the script starts automatically every time we reboot, we'll add it to MATE DE's Startup Applications. Open System > Control Center > Startup Applications and click on Custom Add button. Browse to the location of your script, give it a name (e.g., `auto-rotate-screen`), and click Add.

With these steps complete, we should now witness our auto-rotate screen functionality working seamlessly on our PostmarketOS device running MATE DE.

---

Hope you found this solution as helpful as I did. The process is straightforward, and with a bit of patience, you'll be enjoying an automatically rotating screen in no time!