emacs-exwm / exwm

Emacs X Window Manager
https://elpa.gnu.org/packages/exwm.html
GNU General Public License v3.0
278 stars 14 forks source link

Notification server? #65

Open minad opened 4 months ago

minad commented 4 months ago

Not directly X related, but how would you feel about adding a lightweight notification service here? The following is taken from https://github.com/timor/exwm-ns, so it would need copyright assignment.

;;; exwm-notification.el --- Notification server -*- lexical-binding: t -*-
;;; Commentary: From https://github.com/timor/exwm-ns
;;; Code:

(require 'exwm-core)
(require 'dbus)

(defvar exwm-notification--methods nil)
(defvar exwm-notification--service "org.freedesktop.Notifications")
(defvar exwm-notification--path "/org/freedesktop/Notifications")
(defvar exwm-notification--interface "org.freedesktop.Notifications")

(defun exwm-notification-register-method (method handler)
  (dbus-register-method :session exwm-notification--service
                        exwm-notification--path
                        exwm-notification--interface
                        method handler))

(defun exwm-notification--handle-notify (app-name _replaces-id _app-icon summary
                                         body _actions _hints _expire-timeout)
  (display-message-or-buffer (format "%s: %s - %s %s"
                                     (propertize "Notification" 'face 'warning)
                                     app-name summary body)))

(defun exwm-notification--handle-get-server-information ()
  '("EXWM notification server" "EXWM" "1.0" "1.2"))

(defun exwm-notification--handle-close-notification (id)
  (dbus-send-signal :session exwm-notification--service
                    exwm-notification--path
                    exwm-notification--interface
                    "NotificationClosed" id 3))

(defun exwm-notification--init ()
  (unless exwm-notification--methods
    (if (memq (dbus-register-service :session exwm-notification--service)
              '(:primary-owner :already-owner))
        (setq exwm-notification--methods
              (list
               (exwm-notification-register-method "GetCapabilities" (lambda () '("body")))
               (exwm-notification-register-method "Notify" #'exwm-notification--handle-notify)
               (exwm-notification-register-method "CloseNotification" #'exwm-notification--handle-close-notification)
               (exwm-notification-register-method "GetServerInformation" #'exwm-notification--handle-get-server-information)))
      (message "exwm-notification: Could not register D-Bus service."))))

(defun exwm-notification--exit ()
  (when exwm-notification--methods
    (mapc #'dbus-unregister-object exwm-notification--methods)
    (dbus-unregister-service :session exwm-notification--service)
    (setq exwm-notification--methods nil)))

;;;###autoload
(define-minor-mode exwm-notification-mode
  "Toggle EXWM notification server."
  :global t
  :group 'exwm-notification
  (exwm--global-minor-mode-body notification))

(provide 'exwm-notification)
;;; exwm-notification.el ends here
Stebalien commented 4 months ago

I'd do that as a separate project (and provide users with a reasonable example config, or maybe even an entirely new "EXDE" package).

Personally I use EDNC because it provides a log, the ability to invoke actions, and the ability to display multiple messages at once, clearing them one-by-one as they expire. We could provide a "default" notification server in this repo, but it could easily grow into effectively being its own (opinionated) project.

Stebalien commented 4 months ago

Although, I don't really object if we can get it to a point where it's useful, pluggable, and slim. Providing a better "out of the box" experience would be nice.

progfolio commented 4 months ago

Personally, I'm in favor of keeping this as a separate package.