;; Create Status Notifier items using Emacs ;; ;; StatusNotifier is described in http://www.notmart.org/misc/statusnotifieritem/ ;; ;; Example usage: ;; ;; (defun test-callback (x) ;; (if x ;; (message "activation") ;; (message "secondary activation"))) ;; ;; (setq test-item (register-status-notifier-item "Test" "user-online" 'test-callback)) ;; ;; Then you can unregister from D-Bus using: ;; ;; (unregister-status-notifier-item test-item) ;; ;; TODO: check interface names, creating wrappers to set properties ;; and emit signals according the protocol, support for non-standard images, ;; and a bunch of other things ;-) (require 'dbus) (defconst sn-item-interface "org.kde.StatusNotifierItem" "The interface for Status Notifier items.") (defconst sn-item-path "/StatusNotifierItem" "The object path used by Status Notifier items.") (defun sn-register-activate-handlers (service activate) "Register 'Activate' and 'SecondaryActivate' methods of Status Notifier API. Both will use the same ACTIVATE function, which takes a parameter, t if it's a primary activation or nil if it's a secondary activation." (lexical-let ((act activate)) (dbus-register-method :session service sn-item-path sn-item-interface "Activate" (lambda (x y) (funcall act t))) (dbus-register-method :session service sn-item-path sn-item-interface "SecondaryActivate" (lambda (x y) (funcall act nil))))) (defun sn-register-property (service property value) (dbus-register-property :session service sn-item-path sn-item-interface property :read value)) (defun register-status-notifier-item (title icon-name activate) "Create a Status Notifier item. Register a new Status Notifier item with TITLE and ICON-NAME, and will call the function ACTIVATE when the item is activated. It will return the service name used by the registered item. This name can be used to change Status Notifier properties and to unregister the Status Notifier." (let ((service (format "%s-%d-%s" sn-item-interface (emacs-pid) title))) (sn-register-property service "Category" "ApplicationStatus") (sn-register-property service "Id" title) (sn-register-property service "Title" title) (sn-register-property service "Status" "Active") (sn-register-property service "WindowId" 0) (sn-register-property service "IconName" icon-name) (sn-register-property service "ToolTip" `(:struct :string ,icon-name (:array :signature "(iiay)") :string ,title :string ,title)) (sn-register-activate-handlers service activate) (dbus-call-method :session "org.kde.StatusNotifierWatcher" "/StatusNotifierWatcher" "org.kde.StatusNotifierWatcher" "RegisterStatusNotifierItem" service) service)) (defun unregister-status-notifier-item (service) (dbus-unregister-service :session service))