8

I am trying to keep my laptop running with the lid closed.

What I've done so far is:

  1. In the file /etc/systemd/logind.conf add HandleLidSwitch=ignore both for docked and plain mode. This didn't do the trick at all.
  2. In the file /etc/UPower/UPower.conf set IgnoreLid=true

This worked, but now my TeamViewer session closes and the screen is locked, so I still can't actually use the laptop.

Jeremy
  • 2,846
Hades
  • 81
  • Duplicate of https://askubuntu.com/questions/15520/how-can-i-tell-ubuntu-to-do-nothing-when-i-close-my-laptop-lid – Ben Creasy Aug 18 '19 at 23:19

3 Answers3

12

Command line based

There are some gsettings you can use:

  • Handling when on ac line

     gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'nothing'
    

    This will disable any action when the lid gets closed, and the laptop is plugged into AC.
    To undo simply:

      gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'suspend'
    

    Possible setting values instead of suspend are:

    'blank', 'suspend', 'shutdown','hibernate', 'interactive', 'nothing', 'logout'

  • Handling when on battery

     gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action 'nothing'
    
  • Handling when an external monitor is plugged in

     gsettings set org.gnome.settings-daemon.plugins.power lid-close-suspend-with-external-monitor 'nothing'
    

Using a gui

If you prefer a gui based solution, you have to install

sudo apt install dconf-editor

Invoke with

dconf-editor&

or by searching the program dash.

Go to the /org/gnome/settings-daemon/plugins/power/lid-close-ac-action schema as show in the first line of the images shown above, and make your settings:

enter image description here

li ki
  • 117
abu_bua
  • 10,783
  • Thanks for the clear, well documented, reply. Unfortunately this didn't solve the problem I think the problem is not with the power management but is related to user/log in management killing my session when the lid closes. Or am I looking in the wrong direction? – Hades Jul 27 '18 at 06:17
  • @abu_bua I think you need to upload image again ;-) – Kulfy Aug 07 '18 at 19:27
  • @Hades, regardless if this solved your problem, abu_bua's answer answered your question. Either accept this and make a new question describing the problem or edit your question. – Kurt Nov 20 '18 at 15:59
  • no lid options exist in my menu. – krivar Jan 01 '20 at 15:08
6

On Ubuntu 19.10 the gsettings set org.gnome.settings-daemon.plugins.power lid-close-* actions don't seem to work any more.

Keep on running on lid-close instead of suspend

Edit the file /etc/systemd/logind.conf with sudo and change the line

#HandleLidSwitch=.....

to

HandleLidSwitch=lock

And reboot your system.


The file /etc/systemd/logind.conf controls how logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of
"ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate", and "lock". for these settings:

 HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=, HandleLidSwitch=,
 HandleLidSwitchExternalPower=, HandleLidSwitchDocked=

Reference:

rubo77
  • 32,486
  • Yes working but when I reopened the laptop it changes the resolution of the screen on the higher one! – London Smith Jul 20 '21 at 06:49
  • What do you mean with higher one? Do you use two screens? – rubo77 Jul 20 '21 at 06:53
  • My actual screen resolution is 1600x900, if I close the laptop when I reopen it I get the login screen at 1920x1080 and once logged Gnome has this resolution. I am using only one screen. – London Smith Jul 20 '21 at 08:05
  • As a workaround I would call a script to restore the desired resolution on resume: https://askubuntu.com/q/204073/34298 – rubo77 Jul 20 '21 at 08:20
0

Install GNOME Tweaks. Pull up the user interface and find:

enter image description here

It shouldn't be too hard to figure out what to do:

enter image description here

Close GNOME tweaks to register the change (before testing).