The flow, as I understand it looks like it will be:

1 OS reports about to sleep
2 C code posts an event
3 sleep-wake-mode processes the event
3a Tell the OS to prevent sleep (has to be done in C)
3b Call hooks
3c Tell the OS it's now okay to sleep (ditto in C)

It's 3a and 3c that I was referring to.

On Thu, Feb 6, 2025 at 9:09 AM Michael Albinus <michael.albinus@gmx.de> wrote:
Ship Mints <shipmints@gmail.com> writes:

Hi Ship,

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

Why that? If we have the special event sleep-event, you can call
kbd_buffer_store_event directly in your C source.

The arguments for the sleep-event can be extended as we like, as API.

Best regards, Michael.