naughty: destroy() now takes object instead idx (FS #350)
Fixes the bug although still relies on index being passed with notification in notify() and re-set by arrange(). Also box:geometry() in arrange() stopped working with just one argument so it pushes all coords now. Signed-off-by: koniu <gkusnierz@gmail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
5c8a4dee4a
commit
a48e71af18
|
@ -126,10 +126,9 @@ end
|
||||||
local function arrange()
|
local function arrange()
|
||||||
for p,pos in pairs(notifications) do
|
for p,pos in pairs(notifications) do
|
||||||
for i,notification in pairs(notifications[p]) do
|
for i,notification in pairs(notifications[p]) do
|
||||||
notification.box:geometry({ y = get_offset(i, p, notification.lines).y })
|
local offset = get_offset(i, p, notification.lines)
|
||||||
for w,widget in pairs(notification.box:widgets()) do
|
notification.box:geometry({ x = offset.x, y = offset.y, width = config.width, height = notification.lines * config.height })
|
||||||
widget:buttons({ button({ }, 1, function () destroy(i,p) end), })
|
notification.idx = i
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -138,11 +137,11 @@ end
|
||||||
-- @param idx Index of the notification
|
-- @param idx Index of the notification
|
||||||
-- @param position One of 4 keys in notification dictionary: top_right, top_left, bottom_right, bottom_left
|
-- @param position One of 4 keys in notification dictionary: top_right, top_left, bottom_right, bottom_left
|
||||||
-- @return True if the popup was successfully destroyed, nil otherwise
|
-- @return True if the popup was successfully destroyed, nil otherwise
|
||||||
function destroy(idx, position)
|
function destroy(notification)
|
||||||
if notifications[position][idx] then
|
if notification then
|
||||||
notifications[position][idx].box.screen = nil
|
notification.box.screen = nil
|
||||||
hooks.timer.unregister(notifications[position][idx].timer)
|
hooks.timer.unregister(notification.timer)
|
||||||
table.remove(notifications[position], idx)
|
table.remove(notifications[notification.position], notification.idx)
|
||||||
arrange()
|
arrange()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -197,29 +196,35 @@ function notify(args)
|
||||||
box.ontop = ontop
|
box.ontop = ontop
|
||||||
box.screen = screen
|
box.screen = screen
|
||||||
|
|
||||||
|
local notification = {
|
||||||
|
box = box,
|
||||||
|
lines = lines,
|
||||||
|
position = position,
|
||||||
|
idx = idx
|
||||||
|
}
|
||||||
|
|
||||||
-- populate the wibox with widgets
|
-- populate the wibox with widgets
|
||||||
local textbox = widget({ type = "textbox", name = "text", align = "flex" })
|
local textbox = widget({ type = "textbox", name = "text", align = "flex" })
|
||||||
textbox:buttons({ button({ }, 1, function () destroy(idx, position) end) })
|
textbox:buttons({ button({ }, 1, function () destroy(notification) end) })
|
||||||
textbox.text = string.format('<span font_desc="%s"><b>%s</b> %s</span>',
|
textbox.text = string.format('<span font_desc="%s"><b>%s</b> %s</span>',
|
||||||
config.font, title, text)
|
config.font, title, text)
|
||||||
|
|
||||||
local iconbox = nil
|
local iconbox = nil
|
||||||
if icon then
|
if icon then
|
||||||
iconbox = widget({ type = "imagebox", name = "icon", align = "left" })
|
iconbox = widget({ type = "imagebox", name = "icon", align = "left" })
|
||||||
iconbox:buttons({ button({ }, 1, function () destroy(idx, position) end) })
|
iconbox:buttons({ button({ }, 1, function () destroy(notification) end) })
|
||||||
iconbox.image = image(icon)
|
iconbox.image = image(icon)
|
||||||
iconbox.width = 20
|
iconbox.width = 20
|
||||||
end
|
end
|
||||||
|
|
||||||
box:widgets({ iconbox, textbox })
|
box:widgets({ iconbox, textbox })
|
||||||
|
|
||||||
local timer = function () destroy(idx, position) end
|
local timer = function () destroy(notification) end
|
||||||
hooks.timer.register(timeout, timer)
|
hooks.timer.register(timeout, timer)
|
||||||
|
notification.timer = timer
|
||||||
|
|
||||||
-- insert the notification to the table
|
-- insert the notification to the table
|
||||||
table.insert(notifications[position], { box = box,
|
table.insert(notifications[position],notification)
|
||||||
lines = lines,
|
|
||||||
timer = timer })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue