diff options
| author | Eli Zaretskii | 2025-10-11 14:00:09 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2025-10-11 14:00:09 +0300 |
| commit | dcea973c04bc9f1078444dc1faf9491408832423 (patch) | |
| tree | 0a066feb76e69ab3757655e3cbf8dcb0cfa09d82 /src | |
| parent | c723760f281036f5ae9fe651648ffc707340616d (diff) | |
| download | emacs-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.c | 32 |
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 | ||
| 10343 | enum NI_Severity { | 10343 | enum 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 | ||
| 10406 | static 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. */ |
| 10408 | static EMACS_INT | 10410 | static int |
| 10409 | add_tray_notification (struct frame *f, const char *icon, const char *tip, | 10411 | add_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'. | |||
| 10660 | You can pass the other parameters, but they will be ignored on | 10667 | You can pass the other parameters, but they will be ignored on |
| 10661 | those old systems. | 10668 | those old systems. |
| 10662 | 10669 | ||
| 10663 | There can be at most one active notification at any given time. An | 10670 | There can be at most one active notification at any given time per each |
| 10664 | active notification must be removed by calling `w32-notification-close' | 10671 | Emacs frame. An active notification must be removed by calling the |
| 10665 | before a new one can be shown. | 10672 | function `w32-notification-close', with the same frame selected as the |
| 10673 | one which was selected when the notification was created, before a new | ||
| 10674 | one can be shown for the same frame. The caller must track which | ||
| 10675 | notification was created from which frame, using the returned ID value. | ||
| 10666 | 10676 | ||
| 10667 | usage: (w32-notification-notify &rest PARAMS) */) | 10677 | usage: (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) */) | |||
| 10732 | DEFUN ("w32-notification-close", | 10742 | DEFUN ("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. |
| 10746 | The frame which was selected when the notification was created must | ||
| 10747 | be 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 (); |