aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2025-10-11 14:00:09 +0300
committerEli Zaretskii2025-10-11 14:00:09 +0300
commitdcea973c04bc9f1078444dc1faf9491408832423 (patch)
tree0a066feb76e69ab3757655e3cbf8dcb0cfa09d82 /src
parentc723760f281036f5ae9fe651648ffc707340616d (diff)
downloademacs-dcea973c04bc9f1078444dc1faf9491408832423.tar.gz
emacs-dcea973c04bc9f1078444dc1faf9491408832423.zip
Fix MS-Windows tray notifications from different Emacs frames
* src/w32fns.c (EMACS_TRAY_NOTIFICATION_ID_INIT): Rename from EMACS_TRAY_NOTIFICATION_ID; all users adjusted. (last_tray_notification_id): New static variable. (add_tray_notification): Advance 'last_tray_notification_id' for each new notification; wrap around to the fixed initial value when reached the maximum. This allows Lisp programs track notifications and remove them from the same frame from which they were created. (Fw32_notification_notify, Fw32_notification_close): Doc fixes. * doc/lispref/os.texi (Desktop Notifications): Update the documentation of 'w32-notification-notify' and 'w32-notification-close'. Bug#79400
Diffstat (limited to 'src')
-rw-r--r--src/w32fns.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index 4aaafdd85d3..3fc0f55244f 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -10337,8 +10337,8 @@ typedef struct MY_NOTIFYICONDATAW {
10337#endif 10337#endif
10338 10338
10339 10339
10340#define EMACS_TRAY_NOTIFICATION_ID 42 /* arbitrary */ 10340#define EMACS_TRAY_NOTIFICATION_ID_INIT 42 /* arbitrary */
10341#define EMACS_NOTIFICATION_MSG (WM_APP + 1) 10341#define EMACS_NOTIFICATION_MSG (WM_APP + 1)
10342 10342
10343enum NI_Severity { 10343enum NI_Severity {
10344 Ni_None, 10344 Ni_None,
@@ -10403,14 +10403,16 @@ utf8_mbslen_lim (const char *str, int lim)
10403 return mblen; 10403 return mblen;
10404} 10404}
10405 10405
10406static unsigned short last_tray_notification_id;
10407
10406/* Low-level subroutine to show tray notifications. All strings are 10408/* Low-level subroutine to show tray notifications. All strings are
10407 supposed to be unibyte UTF-8 encoded by the caller. */ 10409 supposed to be unibyte UTF-8 encoded by the caller. */
10408static EMACS_INT 10410static int
10409add_tray_notification (struct frame *f, const char *icon, const char *tip, 10411add_tray_notification (struct frame *f, const char *icon, const char *tip,
10410 enum NI_Severity severity, unsigned timeout, 10412 enum NI_Severity severity, unsigned timeout,
10411 const char *title, const char *msg) 10413 const char *title, const char *msg)
10412{ 10414{
10413 EMACS_INT retval = EMACS_TRAY_NOTIFICATION_ID; 10415 int retval = -1;
10414 10416
10415 if (FRAME_W32_P (f)) 10417 if (FRAME_W32_P (f))
10416 { 10418 {
@@ -10437,7 +10439,12 @@ add_tray_notification (struct frame *f, const char *icon, const char *tip,
10437 else 10439 else
10438 nidw.cbSize = MYNOTIFYICONDATAW_V1_SIZE; /* < W2K */ 10440 nidw.cbSize = MYNOTIFYICONDATAW_V1_SIZE; /* < W2K */
10439 nidw.hWnd = FRAME_W32_WINDOW (f); 10441 nidw.hWnd = FRAME_W32_WINDOW (f);
10440 nidw.uID = EMACS_TRAY_NOTIFICATION_ID; 10442 if (!last_tray_notification_id)
10443 last_tray_notification_id = EMACS_TRAY_NOTIFICATION_ID_INIT;
10444 else
10445 last_tray_notification_id++;
10446 retval = last_tray_notification_id;
10447 nidw.uID = last_tray_notification_id;
10441 nidw.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO; 10448 nidw.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
10442 nidw.uCallbackMessage = EMACS_NOTIFICATION_MSG; 10449 nidw.uCallbackMessage = EMACS_NOTIFICATION_MSG;
10443 if (!*icon) 10450 if (!*icon)
@@ -10660,16 +10667,19 @@ Note that versions of Windows before W2K support only `:icon' and `:tip'.
10660You can pass the other parameters, but they will be ignored on 10667You can pass the other parameters, but they will be ignored on
10661those old systems. 10668those old systems.
10662 10669
10663There can be at most one active notification at any given time. An 10670There can be at most one active notification at any given time per each
10664active notification must be removed by calling `w32-notification-close' 10671Emacs frame. An active notification must be removed by calling the
10665before a new one can be shown. 10672function `w32-notification-close', with the same frame selected as the
10673one which was selected when the notification was created, before a new
10674one can be shown for the same frame. The caller must track which
10675notification was created from which frame, using the returned ID value.
10666 10676
10667usage: (w32-notification-notify &rest PARAMS) */) 10677usage: (w32-notification-notify &rest PARAMS) */)
10668 (ptrdiff_t nargs, Lisp_Object *args) 10678 (ptrdiff_t nargs, Lisp_Object *args)
10669{ 10679{
10670 struct frame *f = SELECTED_FRAME (); 10680 struct frame *f = SELECTED_FRAME ();
10671 Lisp_Object arg_plist, lres; 10681 Lisp_Object arg_plist, lres;
10672 EMACS_INT retval; 10682 int retval;
10673 char *icon, *tip, *title, *msg; 10683 char *icon, *tip, *title, *msg;
10674 enum NI_Severity severity; 10684 enum NI_Severity severity;
10675 unsigned timeout = 0; 10685 unsigned timeout = 0;
@@ -10732,7 +10742,9 @@ usage: (w32-notification-notify &rest PARAMS) */)
10732DEFUN ("w32-notification-close", 10742DEFUN ("w32-notification-close",
10733 Fw32_notification_close, Sw32_notification_close, 10743 Fw32_notification_close, Sw32_notification_close,
10734 1, 1, 0, 10744 1, 1, 0,
10735 doc: /* Remove the MS-Windows tray notification specified by its ID. */) 10745 doc: /* Remove the MS-Windows tray notification specified by its ID.
10746The frame which was selected when the notification was created must
10747be selected when removing the notification. */)
10736 (Lisp_Object id) 10748 (Lisp_Object id)
10737{ 10749{
10738 struct frame *f = SELECTED_FRAME (); 10750 struct frame *f = SELECTED_FRAME ();