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