I've recently bought an HP Spectre x360 convertible laptop, and while everything worked perfectly out of the box in Linux (wifi, bluetooth, touchscreen...) there was just one thing that kept bugging me: the screen auto-rotation feature didn't work.
This meant that "tent mode" wasn't usable (not that I find it very useful, but still), but most importantly that when being held in "tablet mode" the screen remained in landscape view, even though portrait is usually a better fit for browsing the Internet or viewing documents in general (maybe even vertical videos?).
After searching for scripts to fix this on Internet and failing to get the few I found to work, I decided that writing my own would be the fastest solution. I used iio-sensor-proxy to get the inclination angles and xrandr to set the screen orientation.
The python script is actually very simple, it gets the screen's pitch and roll angles and compares them to see which orientation suits the current position better.
- If |y| < |x|-α :
- If x > 0 : Normal
- If x < 0 : Inverted
- If |y| > |x|+α :
- If y > 0 : Left
- If y < 0 : Right