local astal = require("astal") local Widget = require("astal.gtk3").Widget local Gtk = require("astal.gtk3").Gtk local Variable = require("astal").Variable local Notifd = astal.require("AstalNotifd") local lib = require("lib") local bind = astal.bind local timeout = astal.timeout local TIMEOUT_DELAY = 5000 local notifd = Notifd.get_default() local notif_map = lib.varmap({}) function Header(notif) local icon = lib.value_or(notif.app_icon, notif.desktop_entry) return Widget.Box({ class_name = "header", lib.is_true(icon) and Widget.Icon({ class_name = "app-icon", icon = icon, }), Widget.Label({ class_name = "app-name", halign = "START", ellipsize = "END", label = notif.app_name or "", }), Widget.Label({ class_name = "time", hexpand = true, halign = "END", label = lib.time({ time = notif.time }), }), Widget.Button({ on_clicked = function() notif:dismiss() end, Widget.Icon({ icon = "window-close-symbolic" }), }), }) end function Content(notif) return Widget.Box({ class_name = "content", (notif.image and lib.file_exists(notif.image)) and Widget.Box({ valign = "START", class_name = "image", css = string.format("background-image: url('%s')", notif.image), }), (notif.image and lib.is_icon(notif.image)) and Widget.Box({ valign = "START", class_name = "icon-image", Widget.Icon({ icon = notif.image, hexpand = true, vexpand = true, halign = "CENTER", valign = "CENTER", }), }), Widget.Box({ vertical = true, Widget.Label({ class_name = "summary", halign = "START", xalign = 0, ellipsize = "END", label = notif.summary, }), Widget.Label({ class_name = "body", wrap = true, use_markup = true, halign = "START", xalign = 0, justify = "FILL", label = notif.body, }), }), }) end function Notification(notif, id) local function destroy() notif_map.delete(notif.id) end local function setup() timeout(TIMEOUT_DELAY, destroy) end return Widget.EventBox({ class_name = "notification", setup = setup, on_hover_lost = destroy, Widget.Box({ vertical = true, Header(notif), Gtk.Separator({ visible = true }), Content(notif), }), }) end 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(notif_map()) end