55

Since my upgrade to Ubuntu 17.10 there's no option in the settings about what to do when the notebook-lid is closed any more.

enter image description here

Before this function had the options "do nothing" and "suspend" and maybe "shutdown".

The "do nothing" function did something: when the lid was closed, the display went dark and the screen was locked with the password.

My question is how to change the setting so that it's like I'm used to, so that the screen just locks but doesn't suspend when closing the lid.

pomsky
  • 67,112
  • 21
  • 233
  • 243
  • 1
    I have posted a Gnome bug report, please also support adding this to settings, I have bad experiences with them and having lots of people asking for it might help. Here it is: https://bugzilla.gnome.org/show_bug.cgi?id=790043 – conualfy Nov 08 '17 at 04:46
  • To JohnDabc: it seems that you did not follow Legolas's instructions. In order your system to lock when you close the lid, you MUST undo the tweak (that is to Launch Tweaks, go to the "Power" section and ENABLE suspend on lid-close). To cboettig: yes, it is possible using the same method (changing the logind.conf file). You must add the lines below in /etc/systemd/logind.conf [Login] HandleLidSwitch=lock HandleLidSwitchDocked=ignore – Chris.p Dec 11 '17 at 16:01
  • @Chris.p I have Unity Tweak Tool 0.0.7 . I don't see a "Power" section. I have four major areas [Unity, Window Manager, Appearance, System]. None of them has a section called "Power". – Scooter Jan 28 '18 at 01:19
  • FYI, I've just installed Xubuntu 20.04.1 desktop on an HP Etherbook 8440p. I've performed each of the three existing answers: used `gnome-tweaks`, edited `etc/systemd/logind.conf`, and used `dconf-editor`. Even after rebooting, and making sure that none of the performed actions have been reverted, the laptop still locks on closing the lid. – Teemu Leisti Oct 30 '20 at 12:25

3 Answers3

60

To disable suspend on lid-close

  1. Install Tweaks (gnome-tweak-tool) by running

    sudo apt-get install gnome-tweak-tool
    
  2. Launch Tweaks, go to the "Power" section and disable suspend on lid-close.

    screenshot

To enable lock on lid-close

Undo the above steps before following this. Also, SAVE ALL YOUR WORK, the second command would require you to reboot.

  1. Add the lines below in /etc/systemd/logind.conf

    [Login]
    HandleLidSwitch=lock  
    
  2. Run

    sudo systemctl restart systemd-logind
    

Sources

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Legolas
  • 1,693
  • 10
  • 12
  • 1
    thanks, at least closing the lid dont suspends the notebook anymore. but now it really does "nothing" but turning the screen of. after reopening the screen is not locked and i dont need my password. (like usual before 17.10). maybe someone knows how to change this via terminal? –  Nov 02 '17 at 15:53
  • I appended few additional steps. Can you check and confirm? – Legolas Nov 02 '17 at 17:48
  • No. first editing wasn't so easy, since everythings different with 17.10, solution: "sudo gedit admin:///etc/systemd/logind.conf" (via askubuntu.com/a/968196/755218 ) now the last line of the saved file is "HandleLidSwitch=lock". hand to do a hard poweroff after running the command, but when i now close the lid nothing changes. –  Nov 03 '17 at 13:00
  • I have added the exact content of my file in the answer. I have checked it, this works, and yes you would have to do a hard reboot. – Legolas Nov 03 '17 at 14:27
  • 2
    No don't works with me, this is how the file looks after editing and still after reboot: https://i.stack.imgur.com/o9d9P.png –  Nov 03 '17 at 15:11
  • 1
    I have posted a Gnome bug report, please also support adding this to settings, I have bad experiences with them and having lots of people asking for it might help. Here it is: https://bugzilla.gnome.org/show_bug.cgi?id=790043 – conualfy Nov 08 '17 at 04:46
  • In Unity one could configure this lid behavior conditional on the power state -- i.e. suspend when lid is closed on battery power, but do not suspend when lid is closed on AC (e.g. when device may be used in 'clamshell' mode connected to external monitor and keyboard). Is this possible in Gnome in 17.10? – cboettig Dec 05 '17 at 04:21
  • I have Unity Tweak Tool 0.0.7 . I don't see a "Power" section. I have four major areas [Unity, Window Manager, Appearance, System]. None of them has a section called "Power". – Scooter 1 min ago edit – Scooter Jan 28 '18 at 01:21
  • For ubuntu 18.04, after installing gnome-tweak-tool, run `gnome-tweaks`. It has been renamed for ubuntu 18.04 – Gaurav Gupta Jun 20 '18 at 14:24
  • Excellent! Also `HandleLidSwitch=ignore` just turns off the screen and turns it on again when opened, without locking. – Daniel F Oct 06 '18 at 11:47
  • 2
    it didn't work at me, but i don't know why – Guilherme Feb 16 '19 at 01:39
12

In Ubuntu 18.04 Gnome desktop, there is no option in the Settings utility for configuring the laptop lid close actions. And Gnome Tweaks only offers a switch to enable / disable the "Suspend when laptop lid is closed" option.

For those who want it to shut down automatically, hibernate, or do nothing when the laptop lid is closed, here’s how to do it by hacking the configuration file:

  1. Open a terminal by pressing Ctrl+Alt+T or searching for “Terminal” from start menu. When it opens, run the following command:

    sudo gedit /etc/systemd/logind.conf
    
  2. When the files opens, uncomment the line #HandleLidSwitch=suspend by removing # in the beginning, and change the value to :

    • HandleLidSwitch=poweroff: shutdown / power off when lid is closed.
    • HandleLidSwitch=hibernate: hibernate when lid is closed (need to test if hibernate works).
    • HandleLidSwitch=ignore: do nothing.
    • HandleLidSwitch=suspend: suspend laptop when lid is closed.
  3. Save the file and finally restart the Systemd service to apply changes via command:

    systemctl restart systemd-logind.service
    

Source

Fabby
  • 34,341
  • 38
  • 97
  • 191
LuFFy
  • 221
  • 2
  • 5
  • 1
    **LuFFy:** An edit and an upvote. Use 8 spaces instead of 4 when you're indenting or using numbered or bulleted lists. have a look at my [edits](https://askubuntu.com/posts/1097347/revisions) to see how I did it... **;-)** – Fabby Nov 30 '18 at 10:25
  • but i just want to blank, how can i do that? – Guilherme Feb 16 '19 at 02:15
  • this did not work for me... after completing all the above steps, I closed the lid and the computer promptly went to sleep! (update: apparently a fourth step is necessary - after restarting systemd a reboot is needed, which is... weird) – Michael Jul 16 '22 at 21:57
6

You could install dconf-editor to change what happens when lid is closed.

sudo apt-get install dconf-editor

go to org.gnome.settings-daemon.plugins.power in dconf-editor. you can change the value of lid-close-ac-action and lid-close-battery-action for changing the action when lid closed.The possible values are 'suspend','hibernate','logout','shutdown','nothing'.

screenshot

Via CLI would be:

gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action suspend
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Vivin Veerali
  • 161
  • 1
  • 1