Elektrine lite

← Feed

@mazzilius_marsti@lemmy.world

For those running Linux with Window Managers (or Desktop Environments too), how do you make sure that on lid close: the laptop suspends and locks?

2026-05-03 17:12 UTC

Linux is cool, I can do a lot of things with it. If i set a config file in Linux, I am damn sure that it is ran every single time. The code does what you tell it to do. There is 1 thing that always seems to be “black magic”: 1) lid close and suspend 2) lid close and suspend and lock. If we ignore locking for a moment and focus on suspend. I cant seem to figure out why sometimes lid close would suspend immediately, when other time it takes 5 seconds after lid closes. On some days, lid closes would not even suspend !! Did anyone manage to get suspend work 100 %? I cant believe we have tons of great linux tools and years into kernel dev, and still suspend is a hit or miss.

Replies (21)

  • @everett@lemmy.ml 2026-05-03 18:10

    For starters, do you know if your laptop does S3 sleep or S0? I feel like the latter introduces a lot of uncertainty.

    Open ##1959274

  • @bjoern_tantau@swg-empire.de 2026-05-03 18:16

    In KDE it’s just a simple configuration in the power section of the settings. No idea what the general Linux way would be.

    Open ##1959300

  • @anon5621@lemmy.ml 2026-05-03 18:20

    A lot depends on hardware actually, mix of USB Controller, video card, UEFI and etc type of suspeing s3,s0ix so huge fragmentation actually, it so bad that eveb on modern windows it holy crap shit not work because they forced on s2idle. Tell what ur hardware

    Open ##1959305

  • Not sure how lid detection works on Linux because there are so few laptops that ship with Linux. So I’m not sure if there’s a set rule on that. But, Linux can run on like most, if not all, x86-64 Wintel laptops out there, so there’s gotta be a standard. That said, I use Macs at home and Windows at work. It’s hard wired in my brain that when you get up, you ⌘+CTRL+Q on a Mac or Win+L on a Windows box to lock the machine when you get up. Every single time. I don’t care if it’s a laptop or a desktop. The exception is my MacBook because I know exactly what it’ll do, and it’ll do what I want it to. But sometimes I do the three finger salute. So I imagine if I used Linux, I’d just use its 2/3 finger salute to lock workstation before walking away, because that’s my SOP for walking away from any computer. My main phone is an iPhone, but sometimes I use an old Android phone. My SOP for using it is much the same as the iPhone. So if I were using Linux, I wouldn’t treat it any differently. All that being said, I’d expect the lid action to be in the power options like it is in macOS and Windows. But I guess I’d see if it actually does what it says?

    Open ##1959359

  • @warmaster@lemmy.world 2026-05-03 19:00

    I don’t know, I just installed Aurora Linux and everything works by default. I bet your issue is hardware related, maybe you could change something in the bios to make it work.

    Open ##1981227

  • @JoeKrogan@lemmy.world 2026-05-03 19:50

    Kde on debian here. It just works nowadays

    Open ##1996185

  • @Cyber@feddit.uk 2026-05-03 20:09

    Have a look on the Arch Linux wiki around udev and event debugging (evdev?) Depending on whether you’re suspending to RAM or disk will affect the time it takes - and of course, how much stuff it has to suspend. If you’re in the middle of a resource intensive task (which could just be watching a video… all depends…), then whatever is running needs to stop, and possibly has a full buffer which needs processing as suspend could be to the swap file / partition, which may need emptying first. But, it should all work these days.

    Open ##1996679

  • @Maiq@piefed.social 2026-05-03 20:42

    /etc/systemd/logind.conf HandleLidSwitch=suspend

    Open ##1997274

  • @juipeltje@lemmy.world 2026-05-03 21:35

    Depends a bit on your setup. If you’re using systemd you can use the logind.conf as already mentioned, or if you’re on a non-systemd distro you can use the forked elogind, which works pretty much the same way. For locking your session when suspending, since i use wayland, i use swayidle for that. In its config i just put before-sleep ‘swaylock’, which will execute swaylock before the system goes to sleep.

    Open ##1997558

  • @FishFace@piefed.social 2026-05-03 21:26

    You ask too much. Sleep on Linux is never quite as reliable as it should be, and I end up with a laptop gently roasting itself to death in my bag more times than I’d prefer.

    Open ##1997559

  • @boredsquirrel@slrpnk.net 2026-05-04 01:07

    Any normal desktop environment should lock, then suspend. KDE does that afaik, never had that issue.

    Open ##1998200

  • @Peasley@lemmy.world 2026-05-04 02:20

    Suspend and hibernate both work 100% of the time for me so far on both of my laptops, and have for as long as i’ve had them. Thinkpad x270 Fedora (current) KDE spin Thinkpad x250 Ubuntu 24.04 GNOME Fully working since 2019 and 2016 respectively. I have not tested opening the lid after just 5 seconds so i can’t say for sure how long it takes. My previous laptop before these (an x200) would sometimes fail to suspend and get super hot in my bag before running out of battery. I was using Gentoo at the time and i suspect i had something configured incorrectly. It only happened a few times but it was pretty frustrating.

    Open ##1998478

  • @hexagonwin@lemmy.today 2026-05-04 04:19

    i use fvwm. i have win l binded to xlock, so just press win l and close the lid.

    Open ##1998772

  • @utopiah@lemmy.ml 2026-05-04 06:23

    Few seem to address the issue here : it does not work 100% of the time for you. It might work for everybody else but that doesn’t help you much. You have your setup, no theirs. So… you need to investigate. When it works, great, nothing to learn from. When it fails though… can you find a pattern? Does it always fail after you have use something specific? Check lemmy.ml/post/46800646/25494455 which gives examples of potential failure point and journalctl logs. You can then check what failed and if not you can at least know when then backtrack to others logs, e.g. dmesg. They key take away is that when things do not behave as expected you need to put a detective hat on and you investigate : what’s your crime scene? Your laptop and it’s log files what’s the crime? It didn’t suspend properly where are the traces? In the logs where are the logs? Using journalctl or dmesg and typically in /var/log/ what would a good detective do? Search for specific clues, e.g. places where fingerprints do stick, e.g metal or glass, which here would be error messages. That can be found using grep and other tools You also have limited times because the logs will, just like on a real crime scene, get contaminated or rotated or deleted. So… if you do encounter the problem do not rush to the next tasks at hand because you are wasting an opportunity to learn and there is vanishing window. TL;DR : grep logs

    Open ##1999408

  • @mko@discuss.tchncs.de 2026-05-04 08:23

    It works almost all the time. The times it doesn’t usually can be attributed to me not switching off my wireless mouse.

    Open ##1999932

  • @MonkderVierte@lemmy.zip 2026-05-04 09:35

    Suspend is basically the same sensible balance used in booting, so yeah, hit or miss.

    Open ##1999980

  • i dont really close my lid and walk away, i usually just lock the screen and turn off the display if required without suspending. altho i have noticed users complain that suspend fails after a specific service/application is started so u might wanna check on that

    Open ##2001082

  • @fratermus@piefed.social 2026-05-05 14:29

    how do you make sure that on lid close: the laptop suspends and locks? I’ve had it fail (ie, stay on and deplete the battery) often enough over the years that I just suspend/hibernate manually before closure.

    Open ##2040311

  • @TruePe4rl@lemmy.ml 2026-05-05 20:13

    I currently can’t get it working at all and had to disable it, because my machine won’t come back up. So i changed my workflow to take that into account. If I need it closed for a few minutes to move I leave it running and if the time window is greater I turn it off completely. There is always a way, my case is just very specific and I don’t necessarily need it. Anyway, good luck getting it to work the way you like.

    Open ##2044009

  • @Atemu@lemmy.ml 2026-05-06 14:54

    In Hyprland, how it works is that you define the screen lock command (e.g. swaylock) in hypridle and that gets wired into logind somehow such that you can loginctl lock-session. I then (also in hypridle) define a before sleep hook that locks the session. I believe the proper way to do this would be to run your lockscreen as a systemd unit that is WantedBy and Before suspend.target. This would in theory take care of making it idempotent and reliably show the lockscreen before initiating suspend. A friend of mine has this sort of setup and, while it is reliable, the lockscreen is still racy and sometimes only triggers after suspend. Might be the lockscreen unit not signalling its readiness to systemd properly though.

    Open ##2087809

  • @Atemu@lemmy.ml 2026-05-06 15:03

    Inconsistent time before sleep is likely the kernel waiting for IO to sync to disk. Not going to sleep at all implies a serious issue that prevented the kernel from doing so. Check your logs! Suspend reliability greatly depends on the firmware of your specific device as it controls the wakeup. On my Framework 16 for instance, it is very reliable these days. I can’t remember the last time it woke up unexpectedly and I’m not sure whether it happened even once since the firmware update that fixed a major oversight in keyboard wakeup (waking when a key was pressed through a closed lid).

    Open ##2088107