Build the preset values by merging the default preset with the one
actually specified, falling back to the normal preset if no preset is
specified.

This allows changing the position/font/whatever of all notification by
only setting up the default preset value (modulo overrides in the other
presets), instead of having to manually set it in all presets.
---
 lib/naughty.lua.in |   35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in
index cc6a374..be19811 100644
--- a/lib/naughty.lua.in
+++ b/lib/naughty.lua.in
@@ -52,9 +52,9 @@ config.notify_callback = nil
 
 
 --- Notification Presets - a table containing presets for different purposes
--- Preset is a table of any parameters available to notify()
+-- Preset is a table of any parameters available to notify(), overriding 
default
+-- values (@see defaults)
 -- You have to pass a reference of a preset in your notify() call to use the 
preset
--- At least the default preset named "normal" has to be defined
 -- The presets "low", "normal" and "critical" are used for notifications over 
DBUS
 -- @name config.presets
 -- @field low The preset for notifications with low urgency level
@@ -74,7 +74,19 @@ config.presets = {
     }
 }
 
-config.default_preset = config.presets.normal
+-- @name config.defaults
+-- holds the default values for the parameters to @see notify(). These
+-- can optionally be overridden by specifying a preset (@see config.presets)
+-- @class table
+config.defaults = {
+    timeout = 5,
+    text = "",
+    screen = 1,
+    ontop = true,
+    margin = "5",
+    border_width = "1",
+    position = "top_right"
+}
 
 -- DBUS Notification constants
 urgency = {
@@ -279,21 +291,22 @@ function notify(args)
     end
 
     -- gather variables together
-    local preset = args.preset or config.default_preset or {}
-    local timeout = args.timeout or preset.timeout or 5
+    local preset = util.table.join(config.default_preset or {},
+        args.preset or config.presets.normal or {})
+    local timeout = args.timeout or preset.timeout
     local icon = args.icon or preset.icon
     local icon_size = args.icon_size or preset.icon_size
-    local text = args.text or preset.text or ""
+    local text = args.text or preset.text
     local title = args.title or preset.title
-    local screen = args.screen or preset.screen or 1
-    local ontop = args.ontop or preset.ontop or true
+    local screen = args.screen or preset.screen
+    local ontop = args.ontop or preset.ontop
     local width = args.width or preset.width
     local height = args.height or preset.height
     local hover_timeout = args.hover_timeout or preset.hover_timeout
     local opacity = args.opacity or preset.opacity
-    local margin = args.margin or preset.margin or "5"
-    local border_width = args.border_width or preset.border_width or "1"
-    local position = args.position or preset.position or "top_right"
+    local margin = args.margin or preset.margin
+    local border_width = args.border_width or preset.border_width
+    local position = args.position or preset.position
 
     -- beautiful
     local beautiful = bt.get()
-- 
1.7.10.rc3.204.g95589


-- 
To unsubscribe, send mail to [email protected].

Reply via email to