summaryrefslogtreecommitdiff
path: root/pkgs/astal/src/widget/deck
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkgs/astal/src/widget/deck/notifications.lua48
1 files changed, 15 insertions, 33 deletions
diff --git a/pkgs/astal/src/widget/deck/notifications.lua b/pkgs/astal/src/widget/deck/notifications.lua
index 63740ab..6d8f5c9 100644
--- a/pkgs/astal/src/widget/deck/notifications.lua
+++ b/pkgs/astal/src/widget/deck/notifications.lua
@@ -10,38 +10,16 @@ local timeout = astal.timeout
local TIMEOUT_DELAY = 5000
local notifd = Notifd.get_default()
-local notifs = Variable({})
-local map = {}
-
-function update()
- local arr = {}
- for id,_ in pairs(map) do
- table.insert(arr, id)
- end
- notifs:set(arr)
-end
-
-function set(_, id)
- map[id] = true
- update()
-end
-
-function delete(id)
- map[id] = nil
- update()
-end
-
-notifd.on_notified = set
+local notif_map = lib.varmap({})
function Header(notif)
- local show_icon = lib.is_true(notif.app_icon) or
- lib.is_true(notif.desktop_entry)
+ local icon = lib.value_or(notif.app_icon, notif.desktop_entry)
return Widget.Box({
class_name = "header",
- show_icon and Widget.Icon({
+ lib.is_true(icon) and Widget.Icon({
class_name = "app-icon",
- icon = notif.app_icon or notif.desktop_entry,
+ icon = icon,
}),
Widget.Label({
class_name = "app-name",
@@ -56,7 +34,7 @@ function Header(notif)
label = lib.time({ time = notif.time }),
}),
Widget.Button({
- on_clicked = function() delete(notif.id) end,
+ on_clicked = function() notif:dismiss() end,
Widget.Icon({ icon = "window-close-symbolic" }),
}),
})
@@ -103,11 +81,10 @@ function Content(notif)
})
end
-function Notification(id)
- local notif = notifd:get_notification(id)
+function Notification(notif, id)
local function destroy()
- delete(id)
+ notif_map.delete(notif.id)
end
local function setup()
@@ -127,10 +104,15 @@ function Notification(id)
})
end
-function Notifications(ids)
- return lib.map(ids, Notification)
+notifd.on_notified = function(_, id)
+ local notif = notifd:get_notification(id)
+ notif_map.set(id, Notification(notif, id))
+end
+
+notifd.on_resolved = function(_, id)
+ notif_map.delete(id)
end
return function()
- return bind(notifs):as(Notifications)
+ return bind(notif_map())
end