Expose naughty.notifications again

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Daniel 2012-12-15 20:58:18 +01:00 committed by Uli Schlachter
parent 823cd10be7
commit 29b56fd051
1 changed files with 18 additions and 18 deletions

View File

@ -115,12 +115,12 @@ local suspended = false
-- @field width Popup width -- @field width Popup width
-- @field die Function to be executed on timeout -- @field die Function to be executed on timeout
-- @field id Unique notification id based on a counter -- @field id Unique notification id based on a counter
-- @name notifications[screen][position] -- @name naughty.notifications[screen][position]
-- @class table -- @class table
local notifications = { suspended = { } } naughty.notifications = { suspended = { } }
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
notifications[s] = { naughty.notifications[s] = {
top_left = {}, top_left = {},
top_right = {}, top_right = {},
bottom_left = {}, bottom_left = {},
@ -136,11 +136,11 @@ end
--- Resume notifications --- Resume notifications
function naughty.resume() function naughty.resume()
suspended = false suspended = false
for i, v in pairs(notifications.suspended) do for i, v in pairs(naughty.notifications.suspended) do
v.box.visible = true v.box.visible = true
if v.timer then v.timer:start() end if v.timer then v.timer:start() end
end end
notifications.suspended = { } naughty.notifications.suspended = { }
end end
--- Toggle notification state --- Toggle notification state
@ -161,8 +161,8 @@ end
local function get_offset(screen, position, idx, width, height) local function get_offset(screen, position, idx, width, height)
local ws = capi.screen[screen].workarea local ws = capi.screen[screen].workarea
local v = {} local v = {}
local idx = idx or #notifications[screen][position] + 1 local idx = idx or #naughty.notifications[screen][position] + 1
local width = width or notifications[screen][position][idx].width local width = width or naughty.notifications[screen][position][idx].width
-- calculate x -- calculate x
if position:match("left") then if position:match("left") then
@ -174,7 +174,7 @@ local function get_offset(screen, position, idx, width, height)
-- calculate existing popups' height -- calculate existing popups' height
local existing = 0 local existing = 0
for i = 1, idx-1, 1 do for i = 1, idx-1, 1 do
existing = existing + notifications[screen][position][i].height + naughty.config.spacing existing = existing + naughty.notifications[screen][position][i].height + naughty.config.spacing
end end
-- calculate y -- calculate y
@ -187,7 +187,7 @@ local function get_offset(screen, position, idx, width, height)
-- if positioned outside workarea, destroy oldest popup and recalculate -- if positioned outside workarea, destroy oldest popup and recalculate
if v.y + height > ws.y + ws.height or v.y < ws.y then if v.y + height > ws.y + ws.height or v.y < ws.y then
idx = idx - 1 idx = idx - 1
naughty.destroy(notifications[screen][position][1]) naughty.destroy(naughty.notifications[screen][position][1])
v = get_offset(screen, position, idx, width, height) v = get_offset(screen, position, idx, width, height)
end end
if not v.idx then v.idx = idx end if not v.idx then v.idx = idx end
@ -198,8 +198,8 @@ end
-- Re-arrange notifications according to their position and index - internal -- Re-arrange notifications according to their position and index - internal
-- @return None -- @return None
local function arrange(screen) local function arrange(screen)
for p,pos in pairs(notifications[screen]) do for p,pos in pairs(naughty.notifications[screen]) do
for i,notification in pairs(notifications[screen][p]) do for i,notification in pairs(naughty.notifications[screen][p]) do
local offset = get_offset(screen, p, i, notification.width, notification.height) local offset = get_offset(screen, p, i, notification.width, notification.height)
notification.box:geometry({ x = offset.x, y = offset.y }) notification.box:geometry({ x = offset.x, y = offset.y })
notification.idx = offset.idx notification.idx = offset.idx
@ -213,15 +213,15 @@ end
function naughty.destroy(notification) function naughty.destroy(notification)
if notification and notification.box.visible then if notification and notification.box.visible then
if suspended then if suspended then
for k, v in pairs(notifications.suspended) do for k, v in pairs(naughty.notifications.suspended) do
if v.box == notification.box then if v.box == notification.box then
table.remove(notifications.suspended, k) table.remove(naughty.notifications.suspended, k)
break break
end end
end end
end end
local scr = notification.screen local scr = notification.screen
table.remove(notifications[scr][notification.position], notification.idx) table.remove(naughty.notifications[scr][notification.position], notification.idx)
if notification.timer then if notification.timer then
notification.timer:stop() notification.timer:stop()
end end
@ -237,8 +237,8 @@ end
local function getById(id) local function getById(id)
-- iterate the notifications to get the notfications with the correct ID -- iterate the notifications to get the notfications with the correct ID
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
for p,pos in pairs(notifications[s]) do for p,pos in pairs(naughty.notifications[s]) do
for i,notification in pairs(notifications[s][p]) do for i,notification in pairs(naughty.notifications[s][p]) do
if notification.id == id then if notification.id == id then
return notification return notification
end end
@ -482,11 +482,11 @@ function naughty.notify(args)
layout:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die))) layout:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
-- insert the notification to the table -- insert the notification to the table
table.insert(notifications[screen][notification.position], notification) table.insert(naughty.notifications[screen][notification.position], notification)
if suspended then if suspended then
notification.box.visible = false notification.box.visible = false
table.insert(notifications.suspended, notification) table.insert(naughty.notifications.suspended, notification)
end end
-- return the notification -- return the notification