Julien Danjou wrote:
At 1228932410 time_t, Leon Winter wrote:
+ table.foreach(config.mapping, function(i, obj)
+ local filter, preset, s = obj[1], obj[2], 0
+ if filter.urgency and filter.urgency ~= hints.urgency then return end
+ if filter.category and filter.category ~= hints.category then return
end
+ if filter.appname and filter.appname ~= appname then return end
+ table.foreach(filter, function(j, el) s = s + 1 end)
+ if s > score then
+ score = s
+ args.preset = preset
+ end
+ end)
Leon, I'd really suggest to use a pairs() loop.
Hi,
the changed patch is attached. I also removed the local attribute from
.urgency, so we can access to it from rc.lua (naughty.urgency).
The second patch is feature request from Gregor, he wants naughty to be
able to display nil e.g. If you want to talk about that please catch him ;)
Regards,
Leon Winter
>From 59ecf6cbfaf2998928c49914a6e5ac70d573ea44 Mon Sep 17 00:00:00 2001
From: Leon Winter <[EMAIL PROTECTED]>
Date: Thu, 11 Dec 2008 13:53:24 +0100
Subject: [PATCH] naughty: support for categories via mapping
---
lib/naughty.lua.in | 43 +++++++++++++++++++++++++++++++------------
1 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in
index 49f7275..36f5ec0 100644
--- a/lib/naughty.lua.in
+++ b/lib/naughty.lua.in
@@ -98,17 +98,30 @@ config.presets = {
}
}
--- Counter for the notifications
--- Required for later access via DBUS
-local counter = 1
-
-- DBUS Notification constants
-local urgency = {
+urgency = {
low = "\0",
normal = "\1",
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.
-- Each element is a table consisting of:
-- @field box Wibox object containing the popup
@@ -371,7 +384,7 @@ end
-- DBUS/Notification support
-- 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 = {}
if data.member == "Notify" then
if text ~= "" then
@@ -386,12 +399,18 @@ if data.member == "Notify" then
return nil
end
end
- if hints.urgency == urgency.low then
- args.preset = config.presets.low
- elseif hints.urgency == urgency.normal then
- args.preset = config.presets.normal
- elseif hints.urgency == urgency.critical then
- args.preset = config.presets.critical
+ local score = 0
+ 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
if icon ~= "" then
args.icon = icon
--
1.5.6.5
>From 0d9376c9924f118ef2f1037700b3b07c276560de Mon Sep 17 00:00:00 2001
From: Leon Winter <[EMAIL PROTECTED]>
Date: Thu, 11 Dec 2008 13:55:25 +0100
Subject: [PATCH] naughty: convert text and title tostring()
---
lib/naughty.lua.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in
index 36f5ec0..353dd4a 100644
--- a/lib/naughty.lua.in
+++ b/lib/naughty.lua.in
@@ -262,7 +262,7 @@ function notify(args)
local timeout = args.timeout or (args.preset and args.preset.timeout) or config.presets.normal.timeout
local icon = args.icon or (args.preset and args.preset.icon) or config.icon
local icon_size = args.icon_size or (args.preset and args.preset.icon_size) or config.icon_size
- local text = args.text or ""
+ local text = tostring(args.text) or ""
local screen = args.screen or (args.preset and args.preset.screen) or config.presets.normal.screen
local ontop = args.ontop or config.ontop
local width = args.width or (args.preset and args.preset.width) or config.presets.normal.width
@@ -300,7 +300,7 @@ function notify(args)
notification.idx = #notifications[screen][notification.position] + 1
local title = ""
- if args.title then title = args.title .. "\n" end
+ if args.title then title = tostring(args.title) .. "\n" end
-- hook destroy
local die = function () destroy(notification) end
--
1.5.6.5