Factor `awful.rules.apply_do` out of `apply`

This allows to apply properties and callbacks to a client like
awful.rules.apply would do, without the matching part.

This is useful with the new startup notifications, and lets you apply
the same properties and callbacks from e.g. a manage signal handler.
This commit is contained in:
Daniel Hahler 2014-03-16 01:45:31 +01:00 committed by Uli Schlachter
parent fed803a6bc
commit 9a5a8dc6e8
1 changed files with 11 additions and 2 deletions

View File

@ -173,7 +173,7 @@ function rules.does_match(c, rules)
return #result == 0 and false or result return #result == 0 and false or result
end end
--- Apply rules to a client. --- Apply awful.rules.rules to a client.
-- @param c The client. -- @param c The client.
function rules.apply(c) function rules.apply(c)
local props = {} local props = {}
@ -190,6 +190,15 @@ function rules.apply(c)
end end
end end
rules.execute(c, props, callbacks)
end
--- Apply properties and callbacks to a client.
-- @param c The client.
-- @param props Properties to apply.
-- @param callbacks Callbacks to apply.
function rules.execute(c, props, callbacks)
for property, value in pairs(props) do for property, value in pairs(props) do
if property ~= "focus" and type(value) == "function" then if property ~= "focus" and type(value) == "function" then
value = value(c) value = value(c)
@ -220,7 +229,7 @@ function rules.apply(c)
atag.withcurrent(c) atag.withcurrent(c)
end end
-- Apply all callbacks from matched rules. -- Apply all callbacks.
for i, callback in pairs(callbacks) do for i, callback in pairs(callbacks) do
callback(c) callback(c)
end end