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

From: Andrew Cohen <[email-masked]>
Date: Wed, 05 Feb 2025 20:51:42 +0800

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

    EZ> Thanks, and don't hesitate to ask questions where you have
    EZ> difficulties.  I'm sure you will find here quite a few people
    EZ> willing to help.

OK, I have almost no idea what I am doing. I am trying to understand how
to use unread-command-events to make this work. I guess a new event
(sleep-event) will get added in the C code? Then backends other than
dbus will generate this event when a system sleeps or wakes, and we have
a handler installed like

(define-key special-event-map [sleep-event] 'handle-sleep-event)

with the function 'handle-sleep-event that runs the appropriate hooks.

For the dbus backend we install a dbus callback that injects the
sleep-event onto unread-command-events, which would then trigger the
'handle-sleep-event function. 

So I thought I would play around a bit. I tried installing [sleep-event]
in the special-event map, but when I push the sleep-event onto
unread-command-events I get an error: "<sleep-event> is undefined".
After playing around I found that if I also install it in the global
keymap, it works (that is, pushing a sleep-event onto
unread-command-events then triggers the handler).

So how exactly do I add a new sleep-event to the C source? I tried
copying how its done for dbus-event in keyboard.c and termhooks.h (I'm
only trying to create such an event in lisp so I didn't worry about
generating such an event in C). Is this right? And do I always have to
install the handler in the global keymap (just to test this I tried
pushing an existing dbus-event onto unread-command-events, and also get
"dbus-event is undefined" unless I install a handler on the global
keymap. So it seems that I do. I also notice that other special events,
like delete-frame, have handlers installed in both the global keymap and
the special-event-map).

Sorry for the very naive questions. Assuming that my understanding is
correct I think I can make the necessary modifications to the lisp
package. Then the C code to generate the sleep-event on other systems
can be added.

Best,
Andy
-- 
Andrew Cohen