From: copycat-killer Date: Wed, 25 Jan 2017 17:35:30 +0000 (+0100) Subject: calendar: fix async hanging notifications; closes #289 X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/43cd98510a33e9f2d50d315a9bfc31ff8d3062c9?ds=inline;hp=--cc calendar: fix async hanging notifications; closes #289 --- 43cd98510a33e9f2d50d315a9bfc31ff8d3062c9 diff --git a/helpers.lua b/helpers.lua index b1a195c..7c44648 100644 --- a/helpers.lua +++ b/helpers.lua @@ -185,21 +185,6 @@ function helpers.make_widget_textbox() return t end --- shallow copy a table -function helpers.table_shallowcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in pairs(orig) do - copy[orig_key] = orig_value - end - else -- number, string, boolean, etc - copy = orig - end - return copy -end - -- }}} return helpers diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index ba1216c..90c60b4 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -119,10 +119,15 @@ local function worker(args) if alsabar.followtag then preset.screen = awful.screen.focused() end - alsabar.id = naughty.notify ({ - replaces_id = alsabar.id, - preset = preset - }).id + if not alsabar.notification then + alsabar.notification = naughty.notify { + preset = preset, + destroy = function() alsabar.notification = nil end + } + else + naughty.replace_text(alsabar.notification, preset.title, preset.text) + naughty.reset_timeout(alsabar.notification, preset.timeout) + end end) end diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 3ad3498..892d954 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -20,14 +20,10 @@ local tonumber = tonumber local calendar = { offset = 0 } function calendar.hide() - if not calendar.notification then return end - naughty.destroy(calendar.notification) - calendar.notification = nil + naughty.destroy(naughty.getById(calendar.id)) end function calendar.show(t_out, inc_offset, scr) - calendar.hide() - local today = os.date("%d") local offs = inc_offset or 0 local f @@ -69,12 +65,13 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) - calendar.notification = naughty.notify({ - preset = calendar.notification_preset, - text = ws:gsub("\n*$", ""), - icon = calendar.notify_icon, - timeout = t_out or calendar.notification.preset.timeout or 5 - }) + calendar.id = naughty.notify({ + replaces_id = calendar.id, + preset = calendar.notification_preset, + text = ws:gsub("\n*$", ""), + icon = calendar.notify_icon, + timeout = t_out or calendar.notification.preset.timeout or 5 + }).id end) end diff --git a/widgets/fs.lua b/widgets/fs.lua index 312a5e3..4e9f04b 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -61,11 +61,10 @@ local function worker(args) fs.notification_preset = args.notification_preset if not fs.notification_preset then - fs.notification_preset = { - font = "Monospace 10", - fg = "#FFFFFF", - bg = "#000000" - } + fs.notification_preset = naughty.config.defaults + fs.notification_preset.font = "Monospace 10" + fs.notification_preset.fg = "#FFFFFF" + fs.notification_preset.bg = "#000000" end helpers.set_map(partition, false) @@ -125,7 +124,7 @@ local function worker(args) helpers.newtimer(partition, timeout, fs.update) - return fs + return setmetatable(fs, { __index = fs.widget }) end return setmetatable(fs, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index db03b24..5453b1f 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -129,10 +129,15 @@ local function worker(args) if pulsebar.followtag then preset.screen = awful.screen.focused() end - pulsebar.id = naughty.notify ({ - replaces_id = pulsebar.id, - preset = preset - }).id + if not pulsebar.notification then + pulsebar.notification = naughty.notify { + preset = preset, + destroy = function() pulsebar.notification = nil end + } + else + naughty.replace_text(pulsebar.notification, preset.title, preset.text) + naughty.reset_timeout(pulsebar.notification, preset.timeout) + end end) end