naughty: arg 'screen' to notify() is now respected

Signed-off-by: Matthias Schroeder <ms@softimpulse.de>
Signed-off-by: koniu <gkusnierz@gmail.com>
This commit is contained in:
koniu 2008-11-20 16:13:23 +00:00 committed by Julien Danjou
parent d1db6903fa
commit c453d6c611
1 changed files with 29 additions and 25 deletions

View File

@ -16,6 +16,7 @@ local button = button
local capi = { screen = screen } local capi = { screen = screen }
local bt = require("beautiful") local bt = require("beautiful")
local beautiful = bt.get() local beautiful = bt.get()
local screen = screen
--- Notification library --- Notification library
module("naughty") module("naughty")
@ -75,12 +76,15 @@ config.hover_timeout = nil
-- @name notifications[position] -- @name notifications[position]
-- @class table -- @class table
notifications = { notifications = {}
top_left = {}, for s = 1, screen.count() do
top_right = {}, notifications[s] = {
bottom_left = {}, top_left = {},
bottom_right = {}, top_right = {},
} bottom_left = {},
bottom_right = {},
}
end
--- Evaluate desired position of the notification by index - internal --- Evaluate desired position of the notification by index - internal
-- @param idx Index of the notification -- @param idx Index of the notification
@ -89,10 +93,10 @@ notifications = {
-- @param width Popup width (optional) -- @param width Popup width (optional)
-- @return Absolute position in {x, y} dictionary -- @return Absolute position in {x, y} dictionary
local function get_offset(idx, position, height, width) local function get_offset(screen, position, idx, width, height)
local ws = capi.screen[config.screen].workarea local ws = capi.screen[screen].workarea
local v = {} local v = {}
width = width or notifications[position][idx].width or config.width width = width or notifications[screen][position][idx].width or config.width
-- calculate x -- calculate x
if position:match("left") then if position:match("left") then
@ -104,7 +108,7 @@ local function get_offset(idx, position, height, width)
-- 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[position][i].height + config.spacing + config.border_width*2 existing = existing + notifications[screen][position][i].height + config.spacing + config.border_width*2
end end
-- calculate y -- calculate y
@ -117,8 +121,8 @@ local function get_offset(idx, position, height, width)
-- 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
destroy(notifications[position][1]) destroy(notifications[screen][position][1])
v = get_offset(idx, position, height) v = get_offset(screen, position, idx, width, height)
end end
return v return v
@ -126,12 +130,11 @@ 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() local function arrange(screen)
for p,pos in pairs(notifications) do for p,pos in pairs(notifications[screen]) do
for i,notification in pairs(notifications[p]) do for i,notification in pairs(notifications[screen][p]) do
local offset = get_offset(i, p, notification.height) local offset = get_offset(screen, p, i, notification.width, notification.height)
local width = notification.width notification.box:geometry({ x = offset.x, y = offset.y, width = config.width, height = notification.height })
notification.box:geometry({ x = offset.x, y = offset.y, width = width, height = notification.height })
notification.idx = i notification.idx = i
end end
end end
@ -143,10 +146,11 @@ end
-- @return True if the popup was successfully destroyed, nil otherwise -- @return True if the popup was successfully destroyed, nil otherwise
function destroy(notification) function destroy(notification)
if notification then if notification then
notification.box.screen = nil local scr = notification.box.screen
table.remove(notifications[notification.box.screen][notification.position], notification.idx)
hooks.timer.unregister(notification.die) hooks.timer.unregister(notification.die)
table.remove(notifications[notification.position], notification.idx) notification.box.screen = nil
arrange() arrange(scr)
return true return true
end end
end end
@ -177,7 +181,7 @@ function notify(args)
local notification = {} local notification = {}
notification.position = args.position or config.position notification.position = args.position or config.position
notification.idx = #notifications[notification.position] + 1 notification.idx = #notifications[screen][notification.position] + 1
local title = "" local title = ""
if args.title then title = args.title .. "\n" end if args.title then title = args.title .. "\n" end
@ -232,8 +236,8 @@ function notify(args)
else else
notification.height = lines * config.height end notification.height = lines * config.height end
notification.width = width notification.width = width
local offset = get_offset(notification.idx, notification.position, notification.height, notification.width) local offset = get_offset(screen, notification.position, notification.idx, notification.width, notification.height)
notification.box:geometry({ width = width, notification.box:geometry({ width = notification.width,
height = notification.height, height = notification.height,
x = offset.x, x = offset.x,
y = offset.y }) y = offset.y })
@ -244,7 +248,7 @@ function notify(args)
notification.box.widgets = { iconbox, textbox } notification.box.widgets = { iconbox, textbox }
-- insert the notification to the table -- insert the notification to the table
table.insert(notifications[notification.position],notification) table.insert(notifications[screen][notification.position],notification)
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