naughty: check for D-Bus availability

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-01-08 11:39:53 +01:00
parent fae7e5bb8a
commit d74358a2b1
1 changed files with 92 additions and 91 deletions

View File

@ -388,106 +388,107 @@ function notify(args)
end end
-- DBUS/Notification support -- DBUS/Notification support
-- Notify -- Notify
awful.hooks.dbus.register("org.freedesktop.Notifications", function (data, appname, replaces_id, icon, title, text, actions, hints, expire) if awful.hooks.dbus then
args = {} awful.hooks.dbus.register("org.freedesktop.Notifications", function (data, appname, replaces_id, icon, title, text, actions, hints, expire)
if data.member == "Notify" then args = {}
if text ~= "" then if data.member == "Notify" then
args.text = text if text ~= "" then
if title ~= "" then args.text = text
args.title = title if title ~= "" then
end args.title = title
else end
if title ~= "" then
args.text = title
else else
return nil if title ~= "" then
end args.text = title
end else
local score = 0 return nil
for i, obj in pairs(config.mapping) do
local filter, preset, s = obj[1], obj[2], 0
if (not filter.urgency or filter.urgency == hints.urgency) and
(not filter.category or filter.category == hints.category) and
(not filter.appname or filter.appname == appname) then
for j, el in pairs(filter) do s = s + 1 end
if s > score then
score = s
args.preset = preset
end end
end end
end local score = 0
if not args.preset.callback or (type(args.preset.callback) == "function" and for i, obj in pairs(config.mapping) do
args.preset.callback(data, appname, replaces_id, icon, title, text, actions, hints, expire)) then local filter, preset, s = obj[1], obj[2], 0
if icon ~= "" then if (not filter.urgency or filter.urgency == hints.urgency) and
args.icon = icon (not filter.category or filter.category == hints.category) and
(not filter.appname or filter.appname == appname) then
for j, el in pairs(filter) do s = s + 1 end
if s > score then
score = s
args.preset = preset
end
end
end end
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then if not args.preset.callback or (type(args.preset.callback) == "function" and
args.replaces_id = replaces_id args.preset.callback(data, appname, replaces_id, icon, title, text, actions, hints, expire)) then
if icon ~= "" then
args.icon = icon
end
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
args.replaces_id = replaces_id
end
if expire and expire > -1 then
args.timeout = expire / 1000
end
local id = notify(args).id
return "i", id
end end
if expire and expire > -1 then return "i", "0"
args.timeout = expire / 1000 elseif data.member == "CloseNotification" then
local obj = getById(arg1)
if obj then
destroy(obj)
end end
local id = notify(args).id elseif data.member == "GetServerInfo" or data.member == "GetServerInformation" then
return "i", id -- name of notification app, name of vender, version
return "s", "naughty", "s", "awesome", "s", AWESOME_VERSION:match("%d.%d")
end end
return "i", "0" end)
elseif data.member == "CloseNotification" then
local obj = getById(arg1)
if obj then
destroy(obj)
end
elseif data.member == "GetServerInfo" or data.member == "GetServerInformation" then
-- name of notification app, name of vender, version
return "s", "naughty", "s", "awesome", "s", AWESOME_VERSION:match("%d.%d")
end
end)
awful.hooks.dbus.register("org.freedesktop.DBus.Introspectable", awful.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
Introspection 1.0//EN" Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node> <node>
<interface name="org.freedesktop.DBus.Introspectable"> <interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect"> <method name="Introspect">
<arg name="data" direction="out" type="s"/> <arg name="data" direction="out" type="s"/>
</method> </method>
</interface> </interface>
<interface name="org.freedesktop.Notifications"> <interface name="org.freedesktop.Notifications">
<method name="CloseNotification"> <method name="CloseNotification">
<arg name="id" type="u" direction="in"/> <arg name="id" type="u" direction="in"/>
</method> </method>
<method name="Notify"> <method name="Notify">
<arg name="app_name" type="s" direction="in"/> <arg name="app_name" type="s" direction="in"/>
<arg name="id" type="u" direction="in"/> <arg name="id" type="u" direction="in"/>
<arg name="icon" type="s" direction="in"/> <arg name="icon" type="s" direction="in"/>
<arg name="summary" type="s" direction="in"/> <arg name="summary" type="s" direction="in"/>
<arg name="body" type="s" direction="in"/> <arg name="body" type="s" direction="in"/>
<arg name="actions" type="as" direction="in"/> <arg name="actions" type="as" direction="in"/>
<arg name="hints" type="a{sv}" direction="in"/> <arg name="hints" type="a{sv}" direction="in"/>
<arg name="timeout" type="i" direction="in"/> <arg name="timeout" type="i" direction="in"/>
<arg name="return_id" type="u" direction="out"/> <arg name="return_id" type="u" direction="out"/>
</method> </method>
<method name="GetServerInformation"> <method name="GetServerInformation">
<arg name="return_name" type="s" direction="out"/> <arg name="return_name" type="s" direction="out"/>
<arg name="return_vendor" type="s" direction="out"/> <arg name="return_vendor" type="s" direction="out"/>
<arg name="return_version" type="s" direction="out"/> <arg name="return_version" type="s" direction="out"/>
</method> </method>
<method name="GetServerInfo"> <method name="GetServerInfo">
<arg name="return_name" type="s" direction="out"/> <arg name="return_name" type="s" direction="out"/>
<arg name="return_vendor" type="s" direction="out"/> <arg name="return_vendor" type="s" direction="out"/>
<arg name="return_version" type="s" direction="out"/> <arg name="return_version" type="s" direction="out"/>
</method> </method>
</interface> </interface>
</node>]=] </node>]=]
return "s", xml return "s", xml
end end
end) end)
-- listen for dbus notification requests -- listen for dbus notification requests
dbus.request_name("org.freedesktop.Notifications") dbus.request_name("org.freedesktop.Notifications")
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