Created
June 30, 2024 02:21
-
-
Save nuvious/0f19ab07cc3af9fb1c90c83c1ab6f50f to your computer and use it in GitHub Desktop.
Auto rotate 2 in 1 Laptop screens like the Lenovo Flex or Yoga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Template Configuration: | |
# ~/.config/autostart/auto-rotate.desktop | |
# | |
# [Desktop Entry] | |
# Type=Application | |
# Exec=sh -c "export DEVICE=eDP && /usr/bin/auto-rotate" # Change device identifier here | |
# Hidden=false | |
# NoDisplay=false | |
# X-GNOME-Autostart-enabled=true | |
# Name=Auto Rotate Screen | |
# Comment=Automatically rotates the screen based on sensor data | |
if [ -z "$DEVICE" ]; then | |
echo "DEVICE environment variable is not set." | |
echo "Set DEVICE variable in ~/.config/autostart/auto-rotate.desktop" | |
exit 1 | |
fi | |
if ! which monitor-sensor; then | |
echo "Could not find monitor-sensor. Please inatll iio-sensor-proxy." | |
exit 1 | |
fi | |
while IFS= read -r line; do | |
if [[ $line == *"Accelerometer orientation changed:"* ]]; then | |
orientation=$(echo $line | awk '{print $4}') | |
case $orientation in | |
normal) | |
xrandr --output $DEVICE --rotate normal | |
;; | |
left-up) | |
xrandr --output $DEVICE --rotate left | |
;; | |
right-up) | |
xrandr --output $DEVICE --rotate right | |
;; | |
bottom-up) | |
xrandr --output $DEVICE --rotate inverted | |
;; | |
esac | |
fi | |
done < <(monitor-sensor) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Desktop Entry] | |
Type=Application | |
Exec=sh -c "export DEVICE=eDP && /usr/bin/auto-rotate" # Change device identifier here | |
Hidden=false | |
NoDisplay=false | |
X-GNOME-Autostart-enabled=true | |
Name=Auto Rotate Screen | |
Comment=Automatically rotates the screen based on sensor data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment