calendar: fix async hanging notifications; closes #289

This commit is contained in:
copycat-killer 2017-01-25 18:35:30 +01:00
parent 49a4df385e
commit 43cd98510a
5 changed files with 31 additions and 40 deletions

View File

@ -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

View File

@ -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

View File

@ -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({
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

View File

@ -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 })

View File

@ -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