Ubuntu – Screen Rotates After Closing Laptop Lid HP, Ubuntu 18.04.02

18.04display-rotationlaptopsuspend

I have checked other posts about randomly rotating screens, and screens that rotate after sleep. I have tried the following to no avail:

1. Lock Screen Rotation

enter image description here

Problem persists.

2. Disable Gnome Orientation Plugin

$ gsettings set org.gnome.settings-daemon.plugins.orientation active false

Problem persists.

3. Disable/Uninstall iio-sensor-proxy

$ sudo systemctl stop iio-sensor-proxy.service
$ sudo systemctl disable iio-sensor-proxy.service

$ sudo apt-get remove iio-sensor-proxy

Problem persists.

Every time I close the lid, laptop awakes sideways and I have to run:

$ xrandr -o normal

Is there a bug somewhere? Have I missed something?

How can I make xrandr -o normal run every time the laptop wakes from suspend? Maybe a hackish solution, but it might work right?

Best Answer

I don't know if what you describe is a bug, but you can run xrandr -o normal at wake-up from suspend by doing the following (based on this answer and the comment below it):

  1. Create a shell script named xrandr_normal.sh (you can use another name if you wish) that runs your xrandr command:

    nano /path/to/script/xrandr_normal.sh
    

    Put the following inside:

    #!/bin/bash
    DISPLAY=:0.0 ; export DISPLAY
    xrandr -o normal
    
  2. Give execution rights to your script:

    chmod u+x /path/to/script/xrandr_normal.sh
    
  3. Create a service file that will run your script after suspend (you can use whatever name you wish for the service file):

    sudo nano /etc/systemd/system/xrandr_normal.service
    

    Put the following inside:

    [Unit]
    Description=Some description
    Before=sleep.target
    StopWhenUnneeded=yes
    
    [Service]
    User=YOUR_USERNAME
    Type=oneshot
    RemainAfterExit=yes
    ExecStop=/path/to/script/xrandr_normal.sh
    
    [Install]
    WantedBy=sleep.target
    

    Make sure to replace YOUR_USERNAME in the first line below [Service] with your actual username and put the correct path to your script in ExecStop.

  4. Enable the service you created:

    sudo systemctl enable xrandr_normal
    
  5. Start the service:

    sudo systemctl start xrandr_normal
    
  6. As the author of the answer that this one is based on suggests, you can check for errors if the service does not work after suspend with the following command:

    journalctl -u xrandr_normal.service
    
Related Question