On Sun, Nov 8, 2009 at 5:16 PM, Julien Danjou <[email protected]> wrote:
> At 1257689256 time_t, bob wrote:
> > I've tested this and it works for me(tm). Or do you doubt it's usefulness
> ?
>
> No, I doubt it works. There's no variable entry at the line you patch
> the code.
>
>
Ah right stupid mistake, I didn't tested it on master, just against 3.4. New
patch attached. This one I tested against master. I collect all the
callbacks to execute of all matched rules, then execute them after all
properties are set. Is this OK or should I execute them directly when there
is a match ?
Kind regards,
Hiltjo Posthuma
diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in
index 55bcc08..ccee9c8 100644
--- a/lib/awful/rules.lua.in
+++ b/lib/awful/rules.lua.in
@@ -6,6 +6,7 @@
-- Grab environment we need
local client = client
+local table = table
local type = type
local ipairs = ipairs
local pairs = pairs
@@ -47,6 +48,14 @@ module("awful.rules")
-- properties = { tag = mytagobject, switchtotag = true } }
-- </code>
-- </p>
+-- <p>If you want to apply a custom callback to execute when a rule matched, you
+-- can add:
+-- <br/>
+-- <code>
+-- { rule = { class = "dosbox" },
+-- callback = awful.placement.centered }
+-- </code>
+-- </p>
-- <p>Note that all "rule" entries need to match. If any of the entry does not
-- match, the rule won't be applied.</p>
-- <p>If a client matches multiple rules, their applied in the order they are
@@ -82,11 +91,15 @@ end
-- @param c The client.
function apply(c)
local props = {}
+ local callbacks = {}
for _, entry in ipairs(rules) do
if match(c, entry.rule) then
for property, value in pairs(entry.properties) do
props[property] = value
end
+ if entry.callback then
+ table.insert(callbacks, entry.callback)
+ end
end
end
@@ -108,6 +121,12 @@ function apply(c)
c[property] = value
end
end
+
+ -- Apply all callbacks from matched rules.
+ for i, callback in pairs(callbacks) do
+ callback(c)
+ end
+
-- Do this at last so we do not erase things done by the focus
-- signal.
if props.focus then