47

Is it possible to stop my laptop going to sleep when I close the lid?

GNOME 3.20, Fedora 24.


My laptop does not reliably wake from sleep. (It happens to be a hardware issue... I think I basically killed it while trying to replace a wifi card. But I want to keep using it for a while longer).

0

5 Answers 5

53

Install GNOME Tweak Tool and go to the Power section. There's an option to disable the automatic suspend on lid close.

Option details

I compared dconf before and after to find the option, but it turns out that's not how it's implemented. Instead, Tweak Tool creates ~/.config/autostart/ignore-lid-switch-tweak.desktop. The autostart is a script which effectively runs systemd-inhibit --what=handle-lid-switch. So we can see the lid close action is handled purely by systemd-logind.

Alternative route

An alternative would be to edit /etc/systemd/logind.conf to include:

HandleLidSwitch=ignore

This would work all the time, not just when your user is logged in.

14
  • 1
    Also described in the gnome on-line help Commented Sep 2, 2016 at 17:56
  • 6
    Editing /etc/systemd/logind.conf instead of using GNOME Tweak Tool may be better because it works even when GNOME is not running, for example when working at the console.
    – user22304
    Commented Sep 3, 2016 at 17:41
  • 1
    @Ash thanks for the report, if you want to talk about collecting more information on that, it would probably work best elsewhere e.g. a separate question on this site, or a report on the Ubuntu bug tracker.
    – sourcejedi
    Commented Nov 4, 2018 at 16:59
  • 2
    @sourcejedi I've got nvidia graphics -- which may be a big part of the problem :)
    – jocull
    Commented Nov 9, 2018 at 19:50
  • 5
    It sounds like this feature of gnome-tweaks (the "Suspend when lid closed" option) was removed as it was considered out-of-scope for gnome-tweaks. It has been suggested that this feature ought to be implemented in Gnome Settings proper, instead of Tweaks, but that hasn't happened yet. So, it seems that as of Gnome 45 or so, neither Tweaks nor Settings still has an option to prevent systemd from suspending on lid switch. Commented Dec 5, 2023 at 7:58
11

Unfortunately, the inhibitor routes didn't seem to work as advertised for me on openSUSE Tumbleweed (42.1) using GNOME. But, I had success with Systemd masking:

systemctl mask sleep.target suspend.target

To undo the mask, you can use unmask:

systemctl unmask sleep.target suspend.target
2
6

I had solved this issue once before, but apparently recent versions of Fedora (so far from Fedora 28 to 33, inclusive), require two entries now, whereas before only one was required. So:

user$ sudo vi /etc/systemd/logind.conf

HandleLidSwitch=ignore        <---- Set both of these
HandleLidSwitchDocked=ignore  <---- to ignore lid events.

user$ sudo systemctl restart systemd-logind

EDIT: As mentioned by commenters below, you might want to just reboot after making the edits.

2
  • 3
    Thanks! It would be safer to reboot though. If you restart logind on a default Fedora system, your graphical X session(s) will die (same with any Wayland compositor that I know about).
    – sourcejedi
    Commented Oct 24, 2018 at 7:59
  • 1
    This worked great for me! But I would suggest just rebooting also. When I restarted systemd it got weird and I had to kill the machine anyway.
    – jocull
    Commented Nov 9, 2018 at 15:26
4

As NYCeyes says in https://unix.stackexchange.com/a/460405/229223, one line is not the complete solution.

My configuration in /etc/systemd/logind.conf.d/local.conf is:

[Login]
HandleLidSwitch=lock
HandleLidSwitchDocked=ignore
HandleLidSwitchExternalPower=lock
  • Lines 1 & 3 locks the screen when the laptop is mobile or simply charging, similar to tapping the power button on my phone - make secure.
  • Line 2 is to handle plugging in to my docking station (USB-C device with DisplayPort connectors) and lets me close the lid without the laptop assuming I've stopped working, when I'm actually just getting started.

The logind.conf man page from systemd is actually very informative.

1
  • 1
    Thanks, appreciate the answer and links. I found the logind.conf docs interesting. In particular, > LidSwitchIgnoreInhibited= defaults to "yes". This means that when systemd-logind is handling events by itself (no low level inhibitor locks are taken by another application), the lid switch does not respect suspend blockers by default, but the power and sleep keys do. Commented Apr 25, 2021 at 18:02
3

more recent versions of systemd-logind support a new flag to specify the handling of lid-close on external power

$ /etc/systemd/logind.conf
HandleLidSwitch=suspend                # suspend when on battery
HandleLidSwitchExternalPower=ignore    # inhibit suspend when on AC 
HandleLidSwitchDocked=ignore           # inhibit suspend when on external monitor

$> reboot
   ↓or↑
$> sudo systemctl restart systemd-logind  # will kill current X/Wayland session

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .