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

From: Andrew Cohen <[email-masked]>
Date: Thu, 06 Feb 2025 21:02:43 +0800

>>>>> "SM" == Ship Mints <[email-masked]> writes:

    SM> The API on macOS would expose a pair of C functions to lisp, one
    SM> would inhibit sleep, perhaps returning an opaque "cookie", the
    SM> second to revoke the inhibition. The same API can be used to
    SM> prevent macOS from ever sleeping, if the user wanted that.

Great!

So the idea now is:

Turning on sleep-wake-mode:

0.  If on a system with D-Bus and logind, we register a signal for
PrepareForSleep with a handler that generates a synthetic sleep-event on
state change using Michael's recent insert-special-event.

1. Install 'sleep-event-handler on the special-event-map for
[sleep-event].

'sleep-event-handler will inhibit sleep (with whatever method is
appropriate for the system); run the function sleep-handler-function
which is a defcustom defaulting to running the hooks; release the
inhibition.

2. disabling sleep-wake-mode removes 'sleep-event-handler from the
keymap and replaces it with 'ignore.

(alternatively we could ask each system to expose a lisp function or
variable to turn on and off the generation of sleep-events)

Best,
Andy

-- 
Andrew Cohen