naughty: environment cleanup
Makes naughty environment handling same as awful modules: - relevant capi members all go to local capi = {} - relevant awful members are all explicitly required Signed-off-by: koniu <gkusnierz@gmail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
d397d72a8d
commit
2920ed71d7
|
@ -7,19 +7,18 @@
|
||||||
-- Package environment
|
-- Package environment
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local table = table
|
local table = table
|
||||||
local wibox = wibox
|
|
||||||
local image = image
|
|
||||||
local type = type
|
local type = type
|
||||||
local hooks = require("awful.hooks")
|
|
||||||
local string = string
|
local string = string
|
||||||
local widget = widget
|
local capi = { screen = screen,
|
||||||
|
awesome = awesome,
|
||||||
|
dbus = dbus,
|
||||||
|
widget = widget,
|
||||||
|
wibox = wibox,
|
||||||
|
image = image }
|
||||||
|
local hooks = require("awful.hooks")
|
||||||
local button = require("awful.button")
|
local button = require("awful.button")
|
||||||
local util = require("awful.util")
|
local util = require("awful.util")
|
||||||
local capi = { screen = screen, awesome = awesome }
|
|
||||||
local bt = require("beautiful")
|
local bt = require("beautiful")
|
||||||
local screen = screen
|
|
||||||
local awful = awful
|
|
||||||
local dbus = dbus
|
|
||||||
|
|
||||||
--- Notification library
|
--- Notification library
|
||||||
module("naughty")
|
module("naughty")
|
||||||
|
@ -103,7 +102,7 @@ local counter = 1
|
||||||
-- @class table
|
-- @class table
|
||||||
|
|
||||||
notifications = {}
|
notifications = {}
|
||||||
for s = 1, screen.count() do
|
for s = 1, capi.screen.count() do
|
||||||
notifications[s] = {
|
notifications[s] = {
|
||||||
top_left = {},
|
top_left = {},
|
||||||
top_right = {},
|
top_right = {},
|
||||||
|
@ -186,7 +185,7 @@ end
|
||||||
-- @return notification object if it was found, nil otherwise
|
-- @return notification object if it was found, nil otherwise
|
||||||
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, screen.count() do
|
for s = 1, capi.screen.count() do
|
||||||
for p,pos in pairs(notifications[s]) do
|
for p,pos in pairs(notifications[s]) do
|
||||||
for i,notification in pairs(notifications[s][p]) do
|
for i,notification in pairs(notifications[s][p]) do
|
||||||
if notification.id == id then
|
if notification.id == id then
|
||||||
|
@ -204,7 +203,7 @@ local function getIcon(name)
|
||||||
for d, dir in pairs(config.icon_dirs) do
|
for d, dir in pairs(config.icon_dirs) do
|
||||||
for f, format in pairs(config.icon_formats) do
|
for f, format in pairs(config.icon_formats) do
|
||||||
local icon = dir .. name .. "." .. format
|
local icon = dir .. name .. "." .. format
|
||||||
if awful.util.file_readable(icon) then
|
if util.file_readable(icon) then
|
||||||
return icon
|
return icon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -310,7 +309,7 @@ function notify(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create textbox
|
-- create textbox
|
||||||
local textbox = widget({ type = "textbox", align = "flex" })
|
local textbox = capi.widget({ type = "textbox", align = "flex" })
|
||||||
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
||||||
textbox:margin({ right = margin, left = margin, bottom = 2 * margin })
|
textbox:margin({ right = margin, left = margin, bottom = 2 * margin })
|
||||||
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text)
|
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text)
|
||||||
|
@ -320,17 +319,17 @@ function notify(args)
|
||||||
local iconbox = nil
|
local iconbox = nil
|
||||||
if icon then
|
if icon then
|
||||||
-- try to guess icon if the provided one is non-existent/readable
|
-- try to guess icon if the provided one is non-existent/readable
|
||||||
if type(icon) == "string" and not awful.util.file_readable(icon) then
|
if type(icon) == "string" and not util.file_readable(icon) then
|
||||||
icon = getIcon(icon)
|
icon = getIcon(icon)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if we have an icon, use it
|
-- if we have an icon, use it
|
||||||
if icon then
|
if icon then
|
||||||
iconbox = widget({ type = "imagebox", align = "left" })
|
iconbox = capi.widget({ type = "imagebox", align = "left" })
|
||||||
iconbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
iconbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
||||||
local img
|
local img
|
||||||
if type(icon) == "string" then
|
if type(icon) == "string" then
|
||||||
img = image(icon)
|
img = capi.image(icon)
|
||||||
else
|
else
|
||||||
img = icon
|
img = icon
|
||||||
end
|
end
|
||||||
|
@ -345,11 +344,11 @@ function notify(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create container wibox
|
-- create container wibox
|
||||||
notification.box = wibox({ position = "floating",
|
notification.box = capi.wibox({ position = "floating",
|
||||||
fg = fg,
|
fg = fg,
|
||||||
bg = bg,
|
bg = bg,
|
||||||
border_color = border_color,
|
border_color = border_color,
|
||||||
border_width = border_width })
|
border_width = border_width })
|
||||||
|
|
||||||
-- calculate the height
|
-- calculate the height
|
||||||
if not height then
|
if not height then
|
||||||
|
@ -400,8 +399,8 @@ end
|
||||||
|
|
||||||
-- DBUS/Notification support
|
-- DBUS/Notification support
|
||||||
-- Notify
|
-- Notify
|
||||||
if awful.hooks.dbus then
|
if hooks.dbus then
|
||||||
awful.hooks.dbus.register("org.freedesktop.Notifications", function (data, appname, replaces_id, icon, title, text, actions, hints, expire)
|
hooks.dbus.register("org.freedesktop.Notifications", function (data, appname, replaces_id, icon, title, text, actions, hints, expire)
|
||||||
args = { preset = { } }
|
args = { preset = { } }
|
||||||
if data.member == "Notify" then
|
if data.member == "Notify" then
|
||||||
if text ~= "" then
|
if text ~= "" then
|
||||||
|
@ -451,7 +450,7 @@ if awful.hooks.dbus then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if imgdata then
|
if imgdata then
|
||||||
args.icon = image.argb32(hints.icon_data[1], hints.icon_data[2], imgdata)
|
args.icon = capi.image.argb32(hints.icon_data[1], hints.icon_data[2], imgdata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
||||||
|
@ -475,7 +474,7 @@ if awful.hooks.dbus then
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
awful.hooks.dbus.register("org.freedesktop.DBus.Introspectable",
|
hooks.dbus.register("org.freedesktop.DBus.Introspectable",
|
||||||
function (data, text)
|
function (data, text)
|
||||||
if data.member == "Introspect" then
|
if data.member == "Introspect" then
|
||||||
local xml = [=[<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object
|
local xml = [=[<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object
|
||||||
|
@ -519,7 +518,7 @@ if awful.hooks.dbus then
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- listen for dbus notification requests
|
-- listen for dbus notification requests
|
||||||
dbus.request_name("session", "org.freedesktop.Notifications")
|
capi.dbus.request_name("session", "org.freedesktop.Notifications")
|
||||||
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