Subject: bug#79400: 30.2; Windows: w32-notification-notify/-close handle frames incorrectly

From: Raffael Stocker <[email-masked]>
Date: Sun, 07 Sep 2025 14:37:54 +0200

Hi Emacs,

notifications on Windows are implemented incorrectly in the sense that
the implementation assumes that notifications are per process, when in
fact they are per frame.  This causes a bug that doesn't allow a
notification sent from one frame to be closed from another.  To
reproduce:

--8<---------------cut here---------------start------------->8---
$ emacs -Q
;; call the first frame "F1" and evaluate:
(setq idf1 (w32-notification-notify :title "F1" :body "Hailing from F1!"))
-> 42

;; a notification is shown

;; now ‘C-x 5 2’ to create another frame "F2" and evaluate:
(w32-notification-close idf1)
nil

;; the notification persists

;; from frame F2, evaluate:
(setq idf2 (w32-notification-notify :title "F2" :body "Hailing from F2!"))
-> 42

;; another notification is shown, contradicting the documentation of
;; ‘w32-notification-notify’

;; from frame F1, attempt to close the second notification by evaluating:

(w32-notification-close idf2)
nil

;; this closes the *first* notification, the second one persists

;; from frame F2, you can close the second notification by evaluating
;; any of:

(w32-notification-close idf1)
;; or
(w32-notification-close idf2)
--8<---------------cut here---------------end--------------->8---

Note that both ‘idf1’ and ‘idf2’ are always 42.

The problem is that ‘w32-notification-notify’ and
‘w32-notification-close’ use ‘SELECTED_FRAME()’ to call the Windows API.
This is fine for ‘-notify’, but not for ‘-close’, which should instead
pass the frame used in the corresponding call to ‘-notify’.

I would suggest changing the ID returned in ‘w32-notification-notify’ to
a cons cell containing ID and frame.  While this breaks the API of these
functions, with the usual pattern of ‘(let ((id (w32-notification-notify
...))) ...)’ this should not be a problem for Lisp code.

The relevance for the user is that sometimes, when several frames are
open, notifications don't get closed and new ones may not be shown, for
apparently no reason.

Regards,
Raffael