summaryrefslogtreecommitdiff
path: root/pkgs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-06-19 13:12:02 -0400
committerFreya Murphy <freya@freyacat.org>2025-06-19 13:12:02 -0400
commit2cac0bd4c33fb54db8fc4cc2a5fc9d7c49fdb649 (patch)
treeabac1cc70b1d559e34eeef71e5d93cd980314d2b /pkgs
parentrefactor time function in astal lib (diff)
downloaddotfiles-nix-2cac0bd4c33fb54db8fc4cc2a5fc9d7c49fdb649.tar.gz
dotfiles-nix-2cac0bd4c33fb54db8fc4cc2a5fc9d7c49fdb649.tar.bz2
dotfiles-nix-2cac0bd4c33fb54db8fc4cc2a5fc9d7c49fdb649.zip
update astal notifications
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/astal/src/lib.lua62
-rw-r--r--pkgs/astal/src/style/widget/deck.scss4
-rw-r--r--pkgs/astal/src/widget/deck/notifications.lua48
3 files changed, 79 insertions, 35 deletions
diff --git a/pkgs/astal/src/lib.lua b/pkgs/astal/src/lib.lua
index 71a6c65..7fa326a 100644
--- a/pkgs/astal/src/lib.lua
+++ b/pkgs/astal/src/lib.lua
@@ -2,6 +2,7 @@ local astal = require("astal")
local Variable = require("astal").Variable
local Astal = require("astal.gtk3").Astal
local GLib = astal.require("GLib")
+local Gtk = require("astal.gtk3").Gtk
local lib
@@ -149,6 +150,67 @@ lib = {
}, t or {})
return GLib.DateTime.new_from_unix_local(t.time):format(t.format)
end,
+
+ --- astal variable map
+ varmap = function(initial)
+ local map = initial
+ local var = Variable()
+
+ local function notify()
+ local arr = {}
+ for _, value in pairs(map) do
+ table.insert(arr, value)
+ end
+ var:set(arr)
+ end
+
+ local function delete(key)
+ if Gtk.Widget:is_type_of(map[key]) then map[key]:destroy() end
+
+ map[key] = nil
+ end
+
+ notify()
+
+ return setmetatable({
+ set = function(key, value)
+ delete(key)
+ map[key] = value
+ notify()
+ end,
+ delete = function(key)
+ delete(key)
+ notify()
+ end,
+ get = function()
+ return var:get()
+ end,
+ subscribe = function(callback)
+ return var:subscribe(callback)
+ end,
+ }, {
+ __call = function() return var() end,
+ })
+ end,
+
+ --- better or function
+ value_or = function(l, r)
+ if lib.is_true(l) then
+ return l
+ else
+ return r
+ end
+ end,
+
+ --- better and function
+ value_and = function(l, r)
+ if lib.is_false(l) then
+ return l
+ else
+ return r
+ end
+ end,
+
}
return lib
diff --git a/pkgs/astal/src/style/widget/deck.scss b/pkgs/astal/src/style/widget/deck.scss
index cd926f0..d7dd69c 100644
--- a/pkgs/astal/src/style/widget/deck.scss
+++ b/pkgs/astal/src/style/widget/deck.scss
@@ -3,7 +3,7 @@
@return string.unquote("alpha(#{$c},#{$a})");
}
-$deck-scale: $font-size * 5;
+$deck-scale: $font-size * 4;
.deck {
@@ -17,7 +17,7 @@ $deck-scale: $font-size * 5;
background: $bg;
border-radius: $outer-radius;
margin-bottom: $outer-gap;
- min-width: $deck-scale * 5;
+ min-width: $deck-scale * 6;
}
}
}
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