Prevent suspend when lid close in Fedora 40

Hello,

I trying out fedora 40, it’s awesome so far.
I usually close my laptop’s lid and let Youtube video or podcast play in the background.
I can’t do that anymore, when the lid is closed the laptop goes to suspended state.
I can’t prevent that anymore, I used to uncomment directives in /etc/systemd/logind.conf
That config file doesn’t even exist in F40 so I had to make it and add the following:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

Like it is mentioned here That solution doesn’t work anymore.

I tried out sudo systemctl mask suspend.target it works, but it’s not ideal, I want to be able to put my laptop to suspend state when It need to be. Not disable that option completely.

There also another option which works temporarily:
systemd-inhibit --what=handle-lid-switch zenity --info --text='Lid switch suspend blocked while open' --ok-label=Close

This is not ideal as well. I have to use the terminal each time I want to prevent laptop doing to suspended state when I close the lid.

Also, I couldn’t find the gsettings in F40 that control the lid action mentioned here

Is there simple user friendly solution in fedora 40 to prevent the laptop doing to suspended state when the lid is closed?

Thank you very much for your help!

Software Information:

  • Firmware Version: 1.60
  • OS Name: Fedora Linux 40 (Workstation Edition)
  • OS Build: (null)
  • OS Type: 64-bit
  • GNOME Version: 46
  • Windowing System: Wayland
  • Kernel Version: Linux 6.8.7-300.fc40.x86_64
1 Like

I believe that config file was moved to /usr/lib/systemd/logind.conf.

I don’t have a laptop to test currently, but you should be able to do this by changing the #HandleLidSwitch=suspend line in that file to HandleLidSwitch=ignore.

4 Likes

Thank you very much for your speedy reply!
I found that config file in the location you mentioned, did the modification, reboot but didn’t seem to work.
What worked is that I copied that file logind.conf into a folder I created in/etc/systemd/logind.conf.d/ This procedure is mentioned in config file itself.
I find it a bit complicated for a simple functionality. I Hope there would be a simple gui to do this!
This kinda of tinkering is what put some people off Linux adoption.

Thank you again for help!

5 Likes

Thank you very much for your help, Fred Go, people like you the world needs.

I installed it on my notebook to do some labs and I had the same problem related to the notebook lid, but your solution made me dream.

1 Like

Was that in the release notes :thinking: That seems like something that would be important to know.

I have this one-liner for F39 Server:

sudo mkdir -p '/etc/systemd/logind.conf.d' && echo -e "[Login]\nHandleLidSwitch=ignore" | sudo tee '/etc/systemd/logind.conf.d/99-laptop-server.conf' > '/dev/null'

2 Likes

i have done everything written here but my laptop still just goes on suspend when the lid is closed. help.
fedora workstation 40
edit: false alarm. it works fine if you also remove the hashes.

I don’t know the source of this, but thank you for sharing. This is very useful and I have created this script:

#!/bin/sh

WHAT=handle-lid-switch
PID=$(systemd-inhibit --list | grep $WHAT | sed "s/.*$USER//" | cut -d ' ' -f 2)

if [ -z $PID ]; then
        systemd-inhibit --what=$WHAT zenity --info --text='Lid suspend blocked while open' --ok-label=Close &
        echo Started suspend prevention process $!
else
        echo Killing suspend prevention process $PID
        kill $PID
fi

I have assigned a custom keyboard shortcut to run this with Ctrl-Atl-S so I am able to simply press that key-combination and then close the lid without the laptop suspending:

When I re-open the lid and login (laptop would be locked), I immediately just press the key-combo again to turn off the “prevent suspend” behaviour (or simply press the OK button on the zenity dialog).

I actually think this would be a nice feature for the Caffeine extension so I have suggested this in in the open feature request issue. I would then simply use Caffeine to do this… (it already has a keyboard shortcut assignment configuration option).

1 Like