exwm
exwm copied to clipboard
Notification server?
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