Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification server? #65

Open
minad opened this issue Jun 28, 2024 · 3 comments
Open

Notification server? #65

minad opened this issue Jun 28, 2024 · 3 comments

Comments

@minad
Copy link
Member

minad commented Jun 28, 2024

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
Copy link
Contributor

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

  • As you say, it's not directly related to X.
  • There are many ways to implement notification services with different features/preferences. Users will want to pick their own implementation (IMO).
  • There's nothing "tricky" about implementing the protocol itself.

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
Copy link
Contributor

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants