-
-
Save Migacz85/3f544933ce5add438555ba7cd33f0413 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
#This script will automaticly rotate your screen and change correctly touches from the screen. | |
#Before running the script: | |
#go to https://github.com/hadess/iio-sensor-proxy and and follow all steps to install the code. | |
#find your TOUCHPAD, and TRANSFORM, variables. You can find them using | |
#typing in terminal: | |
#xinput list | |
#tested on hp x360 13s-s150sa, manjaro kde | |
#in case when you dont want install iio-sensor-proxy you can use this script: | |
#https://gist.github.com/tuxflo/5b400c86a5ebde871d94c6bff94ad6cb | |
#but screen will only rotate once is executed. | |
#Update this according to output form command: xinput list | |
TOUCHPAD="ELAN Touchscreen" | |
TRANSFORM='Coordinate Transformation Matrix' | |
monitor-sensor | while read line | |
do | |
if [[ $line =~ .*left.* ]] | |
then | |
xrandr -o left | xinput set-prop "$TOUCHPAD" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1 | |
fi | |
if [[ $line =~ .*right.* ]] | |
then | |
xrandr -o right | xinput set-prop "$TOUCHPAD" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1 | |
fi | |
if [[ $line =~ .*bottom-up.* ]] | |
then | |
xrandr -o inverted | xinput set-prop "$TOUCHPAD" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1 | |
fi | |
if [[ $line =~ .*normal.* ]] | |
then | |
xrandr -o normal | xinput set-prop "$TOUCHPAD" "$TRANSFORM" 1 0 0 0 1 0 0 0 1 | |
fi | |
For some reason on Ubuntu 25.04, this script is not working anymore. It used to work 2 years ago... Unfortunately I am not sure if I was using Ubuntu+XFCE or Xubuntu or if that even matters ... I digress.
I've tried the script again and now, it is not working anymore. I've tried switching to Xorg (logging out, settings bottom right, select Xorg, re-login) to no avail. Something must've changed. I "see" the accelerometer but it always returns 0 for xyz.
$ grep . /sys/bus/iio/devices/iio:device0/in_accel_*_raw
/sys/bus/iio/devices/iio:device0/in_accel_x_raw:0
/sys/bus/iio/devices/iio:device0/in_accel_y_raw:0
/sys/bus/iio/devices/iio:device0/in_accel_z_raw:0
I even rebuilt iio-sensor-proxy from https://gitlab.freedesktop.org/hadess/iio-sensor-proxy.git and it didn't help (You might have to rename some things in the meson config to get it to build. Honestly I wouldn't bother)
I am gonna try with a fresh install of Manjaro KDE and see if screen rotation works. Another theory is it being disabled because the "keyboard is still attached" on my laptop? Touchscreen is working fine. Lenovo Yoga 7 14ARB7 btw.
[rant]
Funnily enough, if you're reading this and want to know more, I've even went as far as installing the official Windows 11 Home Edition Bloatware OEM Lenovo Version (with all drivers, Vantage, Ads, Bloat, etc) via the Digital Download Recovery Service (DDRS) of Lenovo.
Even there, the rotation via accelerometer is not functioning.
[/rant]
Didn't work. Restarting iio-sensor-proxy (Ubuntu 25.04)
$ sudo systemctl restart iio-sensor-proxy.service
$ journalctl -u iio-sensor-proxy
[...]
Apr 23 17:43:25 myuser-Y7-14ARB7 systemd[1]: Started iio-sensor-proxy.service - IIO Sensor Proxy service.
Apr 23 17:43:25 myuser-Y7-14ARB7 iio-sensor-prox[7798]: Not a switch [/sys/devices/platform/AMDI0010:02/i2c-2/i2c-ITE8350:00/001>
Apr 23 17:43:25 myuser-Y7-14ARB7 iio-sensor-prox[7798]: Invalid bitmask entry for /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:0>
I give up for now.
You might laugh, but my sensor board cable (on the mainboard next to the fan) became loose so once I unplugged it, cleaned it with IPA and plugged it back in it started working...
For anyone else out there with a Lenovo Yoga 7 14ARB7, this is working great for me now (on Ubuntu 25.04, Xorg instead of Wayland):
#!/bin/bash
# This script will automatically rotate your screen and remap your Wacom devices
# Requires: monitor-sensor (from iio-sensor-proxy), xrandr, xsetwacom
# Update these according to `xinput list` / `xsetwacom --list devices`
OUTPUT="eDP"
WACOM_TOUCH="Wacom HID 52D3 Finger touch"
WACOM_STYLUS="Wacom HID 52D3 Pen stylus"
WACOM_ERASER="Wacom HID 52D3 Pen eraser"
monitor-sensor | while read line; do
if [[ $line =~ .*left.* ]]; then
# left
xrandr --output "$OUTPUT" --rotate left
xsetwacom set "$WACOM_TOUCH" rotate ccw
xsetwacom set "$WACOM_STYLUS" rotate ccw
xsetwacom set "$WACOM_ERASER" rotate ccw
elif [[ $line =~ .*right.* ]]; then
# right
xrandr --output "$OUTPUT" --rotate right
xsetwacom set "$WACOM_TOUCH" rotate cw
xsetwacom set "$WACOM_STYLUS" rotate cw
xsetwacom set "$WACOM_ERASER" rotate cw
elif [[ $line =~ .*bottom-up.* ]]; then
# inverted
xrandr --output "$OUTPUT" --rotate inverted
xsetwacom set "$WACOM_TOUCH" rotate half
xsetwacom set "$WACOM_STYLUS" rotate half
xsetwacom set "$WACOM_ERASER" rotate half
elif [[ $line =~ .*normal.* ]]; then
# normal
xrandr --output "$OUTPUT" --rotate normal
xsetwacom set "$WACOM_TOUCH" rotate none
xsetwacom set "$WACOM_STYLUS" rotate none
xsetwacom set "$WACOM_ERASER" rotate none
fi
done
And this works for Ubuntu 25 (Wayland!)
Preparations:
sudo apt update
sudo apt install python3-dbus iio-sensor-proxy
mkdir -p ~/.local/bin
wget -O ~/.local/bin/gnome-randr.py https://raw.githubusercontent.com/rickybrent/gnome-randr-py/main/gnome-randr.py
chmod +x ~/.local/bin/gnome-randr.py
python3 ~/.local/bin/gnome-randr.py --current # To check for your screenname, probably "eDP-1" but worth checking!
Then, have this in your autostart:
#!/usr/bin/env bash
#
# Auto-rotate screen on Ubuntu >24.04 GNOME/Wayland
# Uses monitor-sensor + gnome-randr-py
OUTPUT="eDP-1" # ← set this to your panel name
RANDR_SCRIPT="$HOME/.local/bin/gnome-randr.py"
monitor-sensor | while read -r line; do
case "$line" in
*left*) python3 "$RANDR_SCRIPT" --output "$OUTPUT" --rotate left ;;
*right*) python3 "$RANDR_SCRIPT" --output "$OUTPUT" --rotate right ;;
*bottom-up*) python3 "$RANDR_SCRIPT" --output "$OUTPUT" --rotate inverted;;
*normal*) python3 "$RANDR_SCRIPT" --output "$OUTPUT" --rotate normal ;;
esac
done
Also struggling with this issue on my Thinkpad X1 Yoga Gen1.
So instead of using xinput, I use
xsetwacom --set 9 Rotate ccw
to rotate the Touch mask CCW, andxsetwacom --set 10 Rotate ccw
to rotate the Stylus touch mask CCW.If I understand this correctly, this script will keep calling
monitor-sensor
but we might not want that, maybe a 1 second sleep in between the read is fine for quick reaction. Or maybe we can create a systemd service that depends on iio-sensor-proxy service to run this script.Just put a modified version of this script on https://gist.github.com/wonbinbk/92e6177ebb21220ec8291c733bd844e8
for those who use Thinkpad X1 Yoga on Manjaro like myself. Works nicely but the way xrandr turn off the screen while rotating is not as smooth as how it works on Fedora.