Auto-rotation

Some user interfaces like Phosh or Plasma Mobile have auto-rotation implemented. Other user interfaces like Xfce4 or MATE don't have native auto-rotation.

Scripts for X11
For X11, there are many scripts around that provide auto-rotation functionality. The following list is a selection, there are many more.

In MATE there is an issue with updating the screen when rotating by xrandr, the wallpaper area doesn't update entirely. It doesn't affect apps, though. In Xfce4 the workspace swticher plugin doesn't scale its size correctly.

Manual horizontal/vertical screen toggle
This is a simple shell script for manual toggle of the screen orientation. Due to its simplicity, it can be easily implemented. Additionally, as it is triggered manually, it doesn't need to have a functional accelerometer sensor.
 * Copy-paste the content of the script into a new text file. Safe the file somewhere, e.g. as ~/rotate_screen.sh. If you don't have a text editor available, install "mousepad" or open a terminal and use "vi".
 * Make the file executable by  (you may need to adapt path and filename).
 * Install packages "xrandr" and "xinput" by.
 * Check the name of your touchscreen device by  and change it in the script ~/rotate_screen.sh after the "set-prop" (twice).
 * Test your script in a terminal by  (may adapt path and name). When trying this via ssh, you have to add DISPLAY=:0 in front:.
 * Add a new command launcher to the panel, click the icon next to the "command" field, navigate to the script and choose it.
 * Done. If you now hit the launcher in the panel, the screen should rotate. Also the touchscreen should work correctly in the new orientation. If it doesn't, something went wrong. In that case, you can test the "xrandr" and "xinput" lines of the script one by one in a terminal.
 * Alternatively to a launcher, a hardware button or Android touch button could be used. This can be set up in the keyboard shortcuts settings.

Auto-rotation shell script
The next shell script uses "iio-sensor-proxy" to access the accelerometer for auto-rotation. It is based on the following website.
 * Copy-paste the content of the script into a new text file, e.g. ~/auto-rotate_screen.sh.
 * Make the file executable by  (may adapt path and filename).
 * Install packages "xrandr", "xinput", "inotify-tools" and "iio-sensor-proxy".
 * Enable the service "iio-sensor-proxy" by.
 * Reboot
 * Open a terminal and check if the command "monitor-sensor" works. Rotate the device and check if the accelerometer output works. Stop the command by Ctrl+C.
 * Check the name of your touchscreen device by  and change it in the script ~/auto-rotate_screen.sh after the "set-prop" (four times).
 * Test your script in a terminal by . Stop it by Ctrl+C. Btw. testing via ssh doesn't work (because of command "monitor-sensor").
 * Add the script to the startup applications and reboot. At Xfce4, that's in Settings -> Session and Startup -> Tab "Application Autostart" -> button "Add" -> click the icon next to the "command" field, navigate to your script and select it.
 * Reboot again. The auto-rotation should now be enabled.
 * To disable/enable auto-rotation, create a launcher with the command for Xfce4 . Name and path may need to be adapted. At MATE in pmOS, which uses the busybox "ps" command, replace the "-ge 1" by "-ge 4" because it counts also the 3x "auto-rotate" that the command itself contains. As an icon, you can choose e.g. "/usr/share/icons/Faenza/emblems/32/emblem-ubuntuone-updating.png" or "/usr/share/icons/Adwaita/symbolic/emblems/emblem-synchronizing-symbolic.svg".

surface autorotate2
Here is an implementation in python3: https://github.com/andrewrembrandt/surface-autorotate2. Packages "xrandr" and "xinput" need to be installed. Additionally, in the top area of the script, the parameters need to be adapted. "sensorname" can be found at  where you have to replace deviceX by the right number for your accelerometer. "displayname" can be found in, the name before "connected primary". "inputnames" is the name of the touchscreen in "xinput --list". The "pennames" array can be emptied.

ScreenRotator
Another possibility is ScreenRotator: https://github.com/GuLinux/ScreenRotator. It needs to be built, as described in the README. It is based on Qt. For GTK-based Xfce4 and MATE that means that Qt libraries need to be installed.

Note:  Compiling ScreenRotator on 32-bit systems might require the patch mentioned in