From 430a4f0d47f0066c0112534844741c7a4e9141f5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 26 Oct 2021 21:11:53 +0200 Subject: utils: factor out singleton notifications --- utils.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'utils.lua') diff --git a/utils.lua b/utils.lua index 6fc40c5..5b40dbb 100644 --- a/utils.lua +++ b/utils.lua @@ -40,7 +40,7 @@ function M.vol_mute_toggle() awful.spawn("amixer -q set Master toggle") end -function M.auto_mute_toggle(notify_tbl, notify_tbl_key) +function M.auto_mute_toggle(wsp) local control = "'Auto-Mute Mode'" awful.spawn.easy_async("amixer sget " .. control, function(stdout, stderr, exitreason, exitcode) @@ -81,14 +81,8 @@ function M.auto_mute_toggle(notify_tbl, notify_tbl_key) return end - local args = { title = "Auto-mute", text = next_item } - - local prev_notify = notify_tbl[notify_tbl_key] - if prev_notify and prev_notify.box.visible then - args.replaces_id = prev_notify.id - end - - notify_tbl[notify_tbl_key] = naughty.notify(args) + M.notify_singleton(wsp, 'auto_mute', + { title = "Auto-mute", text = next_item }) end ) end) @@ -111,4 +105,12 @@ function M.screen_lock() end +function M.notify_singleton(wsp, id, args) + local prev_notify = wsp.notify_tbl[id] + if prev_notify and prev_notify.box.visible then + args.replaces_id = prev_notify.id + end + wsp.notify_tbl[id] = naughty.notify(args) +end + return M -- cgit v1.2.3