send ActionInvoked(default) when widget clicked

This commit is contained in:
Daniel Barlow 2022-02-12 16:57:08 +00:00
parent 94d5c91c70
commit 56a54b4d31

View File

@ -113,13 +113,21 @@
(: :set-body noti.body) (: :set-body noti.body)
(: :set-icon noti.app-icon))) (: :set-icon noti.app-icon)))
(fn default-action [id]
(bus.connection:emit_signal
nil ; destination
dbus-service-attrs.path
dbus-service-attrs.interface
"ActionInvoked"
(GV "(us)" [id "default"])))
(fn make-notification-widget [id] (fn make-notification-widget [id]
(let [summary (Gtk.Label { :name "summary" }) (let [summary (Gtk.Label { :name "summary" })
body (Gtk.Label) body (Gtk.Label)
icon (Gtk.Image) icon (Gtk.Image)
cancel-me (fn [] (delete-notification id)) cancel-me (fn [] (delete-notification id))
event-box (Gtk.EventBox { event-box (Gtk.EventBox {
:on_button_press_event cancel-me :on_button_press_event #(default-action id)
}) })
hbox (Gtk.Box { hbox (Gtk.Box {
:name "notification" :name "notification"
@ -166,6 +174,12 @@
(update-window) (update-window)
id)) id))
(fn parse-actions [list]
(let [out {}]
(for [i 1 (# list) 2]
(tset out (. list i) (. list (+ 1 i))))
out))
(fn make-notification [params] (fn make-notification [params]
{ {
:sender (. params 1) :sender (. params 1)
@ -173,7 +187,7 @@
:app-icon (. params 3) :app-icon (. params 3)
:summary (. params 4) :summary (. params 4)
:body (. params 5) :body (. params 5)
:actions (. params 6) :actions (parse-actions (. params 6))
:hints (. params 7) :hints (. params 7)
:timeout (. params 8) :timeout (. params 8)
}) })
@ -183,7 +197,7 @@
(= interface dbus-service-attrs.interface)) (= interface dbus-service-attrs.interface))
(match method (match method
"GetCapabilities" "GetCapabilities"
(invocation:return_value (GV "as" ["actions"])) (invocation:return_value (GV "as" ["actions" "body" "persistence"]))
"GetServerInformation" "GetServerInformation"
(invocation:return_value (invocation:return_value
@ -218,4 +232,13 @@
(lgi.GObject.Closure handle-dbus-get) (lgi.GObject.Closure handle-dbus-get)
(lgi.GObject.Closure (fn [a] (print "set")))) (lgi.GObject.Closure (fn [a] (print "set"))))
(add-notification {
:app-icon "dialog-information"
:body "This is an example notifiddcation."
:id 3
:sender "notify-send"
:summary "Hello world!"
})
(Gtk:main) (Gtk:main)