diff options
| author | Michael Albinus | 2012-03-07 08:48:16 +0100 |
|---|---|---|
| committer | Michael Albinus | 2012-03-07 08:48:16 +0100 |
| commit | 6612a28444546783cacdd2a6a15bc7ed826d1eb3 (patch) | |
| tree | dc6490247de606f7de431e4f5459cc972be36581 /lisp | |
| parent | a9685db74e15f9c6336850ffda8932ed208c76cd (diff) | |
| download | emacs-6612a28444546783cacdd2a6a15bc7ed826d1eb3.tar.gz emacs-6612a28444546783cacdd2a6a15bc7ed826d1eb3.zip | |
Avoid superfluous registering of signals. (Bug#10807)
* notifications.el (notifications-on-action-object)
(notifications-on-close-object): New defvars.
(notifications-on-action-signal, notifications-on-closed-signal):
Unregister the signal if not needed any longer.
(notifications-notify): Register `notifications-action-signal' or
`notifications-closed-signal', if :on-action or :on-close has been
passed as argument.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/notifications.el | 59 |
2 files changed, 49 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index da2783ede46..d8342df4da5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2012-03-07 Michael Albinus <Michael.Albinus@alcatel-lucent.com> | ||
| 2 | |||
| 3 | Avoid superfluous registering of signals. (Bug#10807) | ||
| 4 | |||
| 5 | * notifications.el (notifications-on-action-object) | ||
| 6 | (notifications-on-close-object): New defvars. | ||
| 7 | (notifications-on-action-signal, notifications-on-closed-signal): | ||
| 8 | Unregister the signal if not needed any longer. | ||
| 9 | (notifications-notify): Register `notifications-action-signal' or | ||
| 10 | `notifications-closed-signal', if :on-action or :on-close has been | ||
| 11 | passed as argument. | ||
| 12 | |||
| 1 | 2012-03-07 Chong Yidong <cyd@gnu.org> | 13 | 2012-03-07 Chong Yidong <cyd@gnu.org> |
| 2 | 14 | ||
| 3 | * cus-start.el: Avoid x-select-enable-clipboard-manager warning on | 15 | * cus-start.el: Avoid x-select-enable-clipboard-manager warning on |
diff --git a/lisp/notifications.el b/lisp/notifications.el index 1b75c2c5702..908cbcaabab 100644 --- a/lisp/notifications.el +++ b/lisp/notifications.el | |||
| @@ -88,25 +88,26 @@ | |||
| 88 | (defvar notifications-on-action-map nil | 88 | (defvar notifications-on-action-map nil |
| 89 | "Mapping between notification and action callback functions.") | 89 | "Mapping between notification and action callback functions.") |
| 90 | 90 | ||
| 91 | (defvar notifications-on-action-object nil | ||
| 92 | "Object for registered on-action signal.") | ||
| 93 | |||
| 91 | (defvar notifications-on-close-map nil | 94 | (defvar notifications-on-close-map nil |
| 92 | "Mapping between notification and close callback functions.") | 95 | "Mapping between notification and close callback functions.") |
| 93 | 96 | ||
| 97 | (defvar notifications-on-close-object nil | ||
| 98 | "Object for registered on-close signal.") | ||
| 99 | |||
| 94 | (defun notifications-on-action-signal (id action) | 100 | (defun notifications-on-action-signal (id action) |
| 95 | "Dispatch signals to callback functions from `notifications-on-action-map'." | 101 | "Dispatch signals to callback functions from `notifications-on-action-map'." |
| 96 | (let* ((unique-name (dbus-event-service-name last-input-event)) | 102 | (let* ((unique-name (dbus-event-service-name last-input-event)) |
| 97 | (entry (assoc (cons unique-name id) notifications-on-action-map))) | 103 | (entry (assoc (cons unique-name id) notifications-on-action-map))) |
| 98 | (when entry | 104 | (when entry |
| 99 | (funcall (cadr entry) id action) | 105 | (funcall (cadr entry) id action) |
| 100 | (remove entry notifications-on-action-map)))) | 106 | (when (and (not (setq notifications-on-action-map |
| 101 | 107 | (remove entry notifications-on-action-map))) | |
| 102 | (when (fboundp 'dbus-register-signal) | 108 | notifications-on-action-object) |
| 103 | (dbus-register-signal | 109 | (dbus-unregister-object notifications-on-action-object) |
| 104 | :session | 110 | (setq notifications-on-action-object nil))))) |
| 105 | nil | ||
| 106 | notifications-path | ||
| 107 | notifications-interface | ||
| 108 | notifications-action-signal | ||
| 109 | 'notifications-on-action-signal)) | ||
| 110 | 111 | ||
| 111 | (defun notifications-on-closed-signal (id &optional reason) | 112 | (defun notifications-on-closed-signal (id &optional reason) |
| 112 | "Dispatch signals to callback functions from `notifications-on-closed-map'." | 113 | "Dispatch signals to callback functions from `notifications-on-closed-map'." |
| @@ -118,16 +119,11 @@ | |||
| 118 | (when entry | 119 | (when entry |
| 119 | (funcall (cadr entry) | 120 | (funcall (cadr entry) |
| 120 | id (cadr (assoc reason notifications-closed-reason))) | 121 | id (cadr (assoc reason notifications-closed-reason))) |
| 121 | (remove entry notifications-on-close-map)))) | 122 | (when (and (not (setq notifications-on-close-map |
| 122 | 123 | (remove entry notifications-on-close-map))) | |
| 123 | (when (fboundp 'dbus-register-signal) | 124 | notifications-on-close-object) |
| 124 | (dbus-register-signal | 125 | (dbus-unregister-object notifications-on-close-object) |
| 125 | :session | 126 | (setq notifications-on-close-object nil))))) |
| 126 | nil | ||
| 127 | notifications-path | ||
| 128 | notifications-interface | ||
| 129 | notifications-closed-signal | ||
| 130 | 'notifications-on-closed-signal)) | ||
| 131 | 127 | ||
| 132 | (defun notifications-notify (&rest params) | 128 | (defun notifications-notify (&rest params) |
| 133 | "Send notification via D-Bus using the Freedesktop notification protocol. | 129 | "Send notification via D-Bus using the Freedesktop notification protocol. |
| @@ -287,10 +283,29 @@ used to manipulate the notification item with | |||
| 287 | (unique-name (dbus-get-name-owner :session notifications-service))) | 283 | (unique-name (dbus-get-name-owner :session notifications-service))) |
| 288 | (when on-action | 284 | (when on-action |
| 289 | (add-to-list 'notifications-on-action-map | 285 | (add-to-list 'notifications-on-action-map |
| 290 | (list (cons unique-name id) on-action))) | 286 | (list (cons unique-name id) on-action)) |
| 287 | (unless notifications-on-action-object | ||
| 288 | (setq notifications-on-action-object | ||
| 289 | (dbus-register-signal | ||
| 290 | :session | ||
| 291 | nil | ||
| 292 | notifications-path | ||
| 293 | notifications-interface | ||
| 294 | notifications-action-signal | ||
| 295 | 'notifications-on-action-signal)))) | ||
| 296 | |||
| 291 | (when on-close | 297 | (when on-close |
| 292 | (add-to-list 'notifications-on-close-map | 298 | (add-to-list 'notifications-on-close-map |
| 293 | (list (cons unique-name id) on-close)))) | 299 | (list (cons unique-name id) on-close)) |
| 300 | (unless notifications-on-close-object | ||
| 301 | (setq notifications-on-close-object | ||
| 302 | (dbus-register-signal | ||
| 303 | :session | ||
| 304 | nil | ||
| 305 | notifications-path | ||
| 306 | notifications-interface | ||
| 307 | notifications-closed-signal | ||
| 308 | 'notifications-on-closed-signal))))) | ||
| 294 | 309 | ||
| 295 | ;; Return notification id | 310 | ;; Return notification id |
| 296 | id)) | 311 | id)) |