naughty: support for categories via mapping
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
709ae7afc7
commit
b4f0e90362
|
@ -98,17 +98,30 @@ config.presets = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Counter for the notifications
|
|
||||||
-- Required for later access via DBUS
|
|
||||||
local counter = 1
|
|
||||||
|
|
||||||
-- DBUS Notification constants
|
-- DBUS Notification constants
|
||||||
local urgency = {
|
urgency = {
|
||||||
low = "\0",
|
low = "\0",
|
||||||
normal = "\1",
|
normal = "\1",
|
||||||
critical = "\2"
|
critical = "\2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- DBUS notification to preset mapping
|
||||||
|
-- @name config.mapping
|
||||||
|
-- The first element is an object containing the filter
|
||||||
|
-- If the rules in the filter matches the associated preset will be applied
|
||||||
|
-- The rules object can contain: urgency, category, appname
|
||||||
|
-- The second element is the preset
|
||||||
|
|
||||||
|
config.mapping = {
|
||||||
|
{{urgency = urgency.low}, config.presets.low},
|
||||||
|
{{urgency = urgency.normal}, config.presets.normal},
|
||||||
|
{{urgency = urgency.critical}, config.presets.critical}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Counter for the notifications
|
||||||
|
-- Required for later access via DBUS
|
||||||
|
local counter = 1
|
||||||
|
|
||||||
--- Index of notifications. See config table for valid 'position' values.
|
--- Index of notifications. See config table for valid 'position' values.
|
||||||
-- Each element is a table consisting of:
|
-- Each element is a table consisting of:
|
||||||
-- @field box Wibox object containing the popup
|
-- @field box Wibox object containing the popup
|
||||||
|
@ -371,7 +384,7 @@ end
|
||||||
-- DBUS/Notification support
|
-- DBUS/Notification support
|
||||||
|
|
||||||
-- Notify
|
-- Notify
|
||||||
awful.hooks.dbus.register("org.freedesktop.Notifications", function (data, arg1, replaces_id, icon, title, text, actions, hints, expire)
|
awful.hooks.dbus.register("org.freedesktop.Notifications", function (data, appname, replaces_id, icon, title, text, actions, hints, expire)
|
||||||
args = {}
|
args = {}
|
||||||
if data.member == "Notify" then
|
if data.member == "Notify" then
|
||||||
if text ~= "" then
|
if text ~= "" then
|
||||||
|
@ -386,12 +399,18 @@ if data.member == "Notify" then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if hints.urgency == urgency.low then
|
local score = 0
|
||||||
args.preset = config.presets.low
|
for i, obj in pairs(config.mapping) do
|
||||||
elseif hints.urgency == urgency.normal then
|
local filter, preset, s = obj[1], obj[2], 0
|
||||||
args.preset = config.presets.normal
|
if (not filter.urgency or filter.urgency == hints.urgency) and
|
||||||
elseif hints.urgency == urgency.critical then
|
(not filter.category or filter.category == hints.category) and
|
||||||
args.preset = config.presets.critical
|
(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 icon ~= "" then
|
if icon ~= "" then
|
||||||
args.icon = icon
|
args.icon = icon
|
||||||
|
|
Loading…
Reference in New Issue