I prefer using a mode, it seems more idiomatic. Shall this use cl-defgeneric in sleep-wake-mode that each system can specialize? On Thu, Feb 6, 2025 at 8:02 AM Andrew Cohen wrote: > >>>>> "SM" == Ship Mints 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 >