delete notifications by clicking them

maybe we want to change this for swipe right? in android a click takes
you to the app that notified
This commit is contained in:
Daniel Barlow 2022-02-11 23:30:28 +00:00
parent 2166db979c
commit ee3ee99680

View File

@ -91,23 +91,37 @@
(print id (widget:get_parent)) (print id (widget:get_parent))
(if (not (widget:get_parent)) (if (not (widget:get_parent))
(window.box:pack_start widget false false 5))) (window.box:pack_start widget false false 5)))
(if (next notifications) (window.window:show_all) (window:hide))) (if (next notifications)
(window.window:show_all)
(window.window:hide)))
(var notification-id 10) (var notification-id 10)
(fn next-notification-id [] (fn next-notification-id []
(set notification-id (+ notification-id 1)) (set notification-id (+ notification-id 1))
notification-id) notification-id)
(fn delete-notification [id]
(let [widget (. notifications id)]
(tset notifications id nil)
(print "delete " id widget (inspect notifications))
(window.box:remove widget)
(update-window)
))
(fn update-notification-widget [widget noti] (fn update-notification-widget [widget noti]
(doto widget (doto widget
(: :set-summary noti.summary) (: :set-summary noti.summary)
(: :set-body noti.body) (: :set-body noti.body)
(: :set-icon noti.app-icon))) (: :set-icon noti.app-icon)))
(fn make-notification-widget [] (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))
event-box (Gtk.EventBox {
:on_button_press_event cancel-me
})
hbox (Gtk.Box { hbox (Gtk.Box {
:name "notification" :name "notification"
:orientation Gtk.Orientation.HORIZONTAL :orientation Gtk.Orientation.HORIZONTAL
@ -117,6 +131,7 @@
(vbox:pack_start body true false 0) (vbox:pack_start body true false 0)
(hbox:pack_start icon false false 0) (hbox:pack_start icon false false 0)
(hbox:pack_start vbox true true 0) (hbox:pack_start vbox true true 0)
(event-box:add hbox)
{ {
:set-summary (fn [self value] :set-summary (fn [self value]
(set summary.label value)) (set summary.label value))
@ -129,12 +144,12 @@
value value
Gtk.IconSize.DND Gtk.IconSize.DND
))) )))
:widget hbox :widget event-box
})) }))
(fn add-notification [noti] (fn add-notification [noti]
(let [id (if (= noti.id 0) (next-notification-id) noti.id) (let [id (if (= noti.id 0) (next-notification-id) noti.id)
widget (or (. notifications id) (make-notification-widget))] widget (or (. notifications id) (make-notification-widget id))]
(update-notification-widget widget noti) (update-notification-widget widget noti)
(tset notifications id widget.widget) (tset notifications id widget.widget)
(update-window) (update-window)