scratch-screen-share/maybe-signals.lisp

32 lines
1.2 KiB
Common Lisp

(defpackage #:notification-example
(:use #:cl #:dbus)
(:export #:listen-for-notifications))
(in-package #:notification-example)
(define-dbus-object root-object
(:path "/"))
(define-dbus-signal-handler (root-object on-notification-closed) ((id :uint32) (reason :uint32))
(:interface "org.freedesktop.Notifications")
(:name "NotificationClosed")
(format t "Notification ~A closed for reason ~A~%" id reason))
(define-dbus-signal-handler (root-object on-action-invoked) ((id :uint32) (action-key :string))
(:interface "org.freedesktop.Notifications")
(:name "ActionInvoked")
(format t "Action ~A invoked on notification ~A~%" action-key id))
(defun listen-for-notifications ()
(with-open-bus (bus (session-server-addresses))
(format t "Bus connection name: ~A~%" (bus-name bus))
(add-match bus :type :signal
:interface "org.freedesktop.Notifications"
:member "NotificationClosed")
(add-match bus :type :signal
:interface "org.freedesktop.Notifications"
:member "ActionInvoked")
(publish-objects bus)
(format t "Listening for notification signals...~%")
(loop (sleep 1)
(format t ".")
(force-output))))