awful.rules: Implement callbacks for individual properties

When a property is now set to a function, the function's return value will be
used for the value of the property. The function gets the new client as its only
argument.

There is no property which accepts a function as its value and thus this change
can't break anything (yeah, famous last words...).

This should fix half of FS#1011. Panels now don't get focused by awful.rules.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-07-06 17:30:35 +02:00
parent 29b09cf7da
commit 48c6c11d17
2 changed files with 7 additions and 2 deletions

View File

@ -334,7 +334,7 @@ awful.rules.rules = {
{ rule = { },
properties = { border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = true,
focus = awful.client.focus.filter,
keys = clientkeys,
buttons = clientbuttons } },
{ rule = { class = "MPlayer" },

View File

@ -65,6 +65,8 @@ local rules = {}
-- <p>If a client matches multiple rules, their applied in the order they are
-- put in this global rules table. If the value of a rule is a string, then the
-- match function is used to determine if the client matches the rule.</p>
-- <p>If the value of a property is a function, that function gets called and
-- function's return value is used for the property.</p>
--
-- <p> To match multiple clients to a rule one need to use slightly different
-- syntax:
@ -165,6 +167,9 @@ function rules.apply(c)
end
for property, value in pairs(props) do
if property ~= "focus" and type(value) == "function" then
value = value(c)
end
if property == "floating" then
aclient.floating.set(c, value)
elseif property == "tag" then
@ -198,7 +203,7 @@ function rules.apply(c)
-- Do this at last so we do not erase things done by the focus
-- signal.
if props.focus then
if props.focus and (type(props.focus) ~= "function" or props.focus(c)) then
client.focus = c
end
end