How can I rotate my display in the most easy way?

Go into Keyboard -> Shortcuts, select "Custom Shortcuts", and press "+" to add a new shortcut.

"Name" is a descriptive name for the action (i.e. "Rotate monitor"). In "Command" type the custom command to run when the shortcut is activated.

Once the shortcut is in the list, select its row, press ENTER, then the key combination you want to activate the shortcut. If there's a conflict, the shortcut manager will tell you so, and you can choose a different combination.

You can have shortcut to enable rotated display and another to bring it back to an upright position. You can even, if you're knowledgeable enough, write a command that maintains state and just toggles between upright/rotated.

Now, as for the command you need to use, it's probably xrandr:

xrandr --output HDMI1 --rotate left

xrandr --output HDMI1 --rotate normal

The output parameter depends on which port your monitor is plugged into. To see what you currently have, type:

xrandr -q

Mine says:

Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192
LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
   1366x768       60.0*+
   1360x768       59.8     60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA2 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)

In this case my --output would be LVDS1, as all the others are disconnected.


Works great with

xrandr --output LVDS1 --rotate left
xrandr --output LVDS1 --rotate right
xrandr --output LVDS1 --rotate inverted
xrandr --output LVDS1 --rotate normal

Here is a nice example on how to do it based on sensor input: https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu

So basically try the above to identify the screen you want to see rotated. Depending on the model monitor there may be a sensor that sends a signal?

This works nicely for my Lenovo Yoga 2 11 with builtin rotation sensor and it moves the unity dock too.

The script:

#!/bin/sh
# Auto rotate screen based on device orientation

# Receives input from monitor-sensor (part of iio-sensor-proxy package)
# Screen orientation and launcher location is set based upon accelerometer position
# Launcher will be on the left in a landscape orientation and on the bottom in a portrait orientation
# This script should be added to startup applications for the user

# Clear sensor.log so it doesn't get too long over time
> sensor.log

# Launch monitor-sensor and store the output in a variable that can be parsed by the rest of the script
monitor-sensor >> sensor.log 2>&1 &

# Parse output or monitor sensor to get the new orientation whenever the log file is updated
# Possibles are: normal, bottom-up, right-up, left-up
# Light data will be ignored
while inotifywait -e modify sensor.log; do
# Read the last line that was added to the file and get the orientation
ORIENTATION=$(tail -n 1 sensor.log | grep 'orientation' | grep -oE '[^ ]+$')

# Set the actions to be taken for each possible orientation
case "$ORIENTATION" in
normal)
xrandr --output eDP1 --rotate normal && gsettings set com.canonical.Unity.Launcher launcher-position Left ;;
bottom-up)
xrandr --output eDP1 --rotate inverted && gsettings set com.canonical.Unity.Launcher launcher-position Left ;;
right-up)
xrandr --output eDP1 --rotate right && gsettings set com.canonical.Unity.Launcher launcher-position Bottom ;;
left-up)
xrandr --output eDP1 --rotate left && gsettings set com.canonical.Unity.Launcher launcher-position Bottom ;;
esac
done

and prerequisite for the sensors:

sudo apt install iio-sensor-proxy inotify-tools

Tags:

Display