Subject: bug#63620: 30.0.50; [Feature Request] run hooks on sleep/wake

From: Andrew Cohen <[email-masked]>
Date: Thu, 06 Feb 2025 23:36:34 +0800

>>>>> "EZ" == Eli Zaretskii <[email-masked]> writes:

[...]

    EZ> What is the semantics of this?  If the user closes the lid of
    EZ> the laptop, and that was defined to put the system to sleep,
    EZ> does such "inhibiting" mean the system will not sleep?  If so,
    EZ> I'm not sure this is supported.  Or do you mean to delay sleep
    EZ> which is triggered by prolonged enough lack of activity?

The former.  Here is how it works for logind (which is common for
gnu/linux desktops):

logind, as part of the desktop system,  takes responsibility for sleep
initiated through the desktop: that is, through a lack of activity, an
explicit hibernate command (maybe a keypress or a menu item) or through
a lid switch, for example. When a sleep request is initiated this way,
it is announced through D-Bus (the PrepareForSleep signal); D-Bus also
has methods that can control the behavior. An "Inhibit" method can be
called which inhibits the sleep process, even if the lid is now closed,
for example. (This inhibition can just be a delay, or it can be a full
block depending on the parameters passed to "Inhibit"); as long as the
block is in place the system will not sleep. The "Inhibit" method
returns a file descriptor, and the block remains in force until the file
descriptor is closed.

It is, of course, possible to trigger hibernation outside of the desktop
system (directly to the kernel, for example), and this is not controlled
through D-Bus.

My daily routine involves a laptop moving from home to office, and I
rarely log out of the desktop or shutdown. So I typically just shut the
lid which triggers hibernation, and rely on sleep-wake-mode to manage
gnus network connections and my vpn. I had never bothered inhibiting the
sleep since Emacs was always fast enough to complete in time, but the
right thing is certainly to call the "Inhibit" method. Other systems are
likely different.

Best,
Andy

-- 
Andrew Cohen