Skip to content

Instantly share code, notes, and snippets.

@Migacz85
Last active April 27, 2025 14:25
Show Gist options
  • Save Migacz85/3f544933ce5add438555ba7cd33f0413 to your computer and use it in GitHub Desktop.
Save Migacz85/3f544933ce5add438555ba7cd33f0413 to your computer and use it in GitHub Desktop.
Autorotation of your linux display script. Tested on Manjaro KDE, firstly go to https://github.com/hadess/iio-sensor-proxy, make and install (dont worry that is for GNOME ). When installed correctly monitor-sensor should work from command line giving you outputs from sensors. On the end make that script, and execute. It should work. Enjoy :)
#!/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
@lacksfish
Copy link

lacksfish commented Apr 27, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment