diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-10-26 21:11:53 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-10-26 21:11:53 +0200 |
commit | 430a4f0d47f0066c0112534844741c7a4e9141f5 (patch) | |
tree | 7468ceba084fbfd62f3ef613a10d6860c88d4eab /utils.lua | |
parent | 43470e3b516b49e7bdb7559e9ed0af0809d16212 (diff) |
utils: factor out singleton notifications
Diffstat (limited to 'utils.lua')
-rw-r--r-- | utils.lua | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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 |