summaryrefslogtreecommitdiff
path: root/examples/lua/notification-popups/lib.lua
diff options
context:
space:
mode:
authorKevin <[email protected]>2024-10-14 11:56:20 -0300
committerKevin <[email protected]>2024-10-16 00:46:57 -0300
commit1a1c8a605c8011056a07d69b15153bcdec4c0ceb (patch)
tree8967d5eb42c97b3446b407e82ecc3ddbd9f0c440 /examples/lua/notification-popups/lib.lua
parent9e255738f835c0e47cc6ae4d0cfbb96a261b4a2f (diff)
notifications lua example
Diffstat (limited to 'examples/lua/notification-popups/lib.lua')
-rw-r--r--examples/lua/notification-popups/lib.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/lua/notification-popups/lib.lua b/examples/lua/notification-popups/lib.lua
new file mode 100644
index 0000000..2ae71a9
--- /dev/null
+++ b/examples/lua/notification-popups/lib.lua
@@ -0,0 +1,52 @@
+local Variable = require("astal").Variable
+local astal = require("astal")
+local Gtk = astal.Gtk
+
+local M = {}
+
+function M.src(path)
+ local str = debug.getinfo(2, "S").source:sub(2)
+ local src = str:match("(.*/)") or str:match("(.*\\)") or "./"
+ return src .. path
+end
+
+---@generic T, R
+---@param arr T[]
+---@param func fun(T, integer): R
+---@return R[]
+function M.map(arr, func)
+ local new_arr = {}
+ for i, v in ipairs(arr) do
+ new_arr[i] = func(v, i)
+ end
+ return new_arr
+end
+
+---@param name string
+---@param size? 16 | 32 | 64 | 128 | 256 | 512 | number
+function M.lookup_icon(name, size)
+ if not name or #name == 0 then
+ return
+ end
+ size = size or 256
+
+ local theme = Gtk.IconTheme.get_default()
+ local icon_info, path
+
+ for _, n in ipairs({
+ name,
+ string.lower(name),
+ string.upper(name),
+ }) do
+ icon_info = theme:lookup_icon(n, size, "USE_BUILTIN")
+
+ if icon_info then
+ return icon_info
+ end
+ end
+ return false
+end
+
+M.date = Variable(""):poll(1000, "date")
+
+return M