From 48c6c11d1721f40ec5136cfbd4a8125e4208277f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 6 Jul 2012 17:30:35 +0200 Subject: [PATCH] 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 --- awesomerc.lua.in | 2 +- lib/awful/rules.lua.in | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index bfc5791ee..bdf0c290c 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -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" }, diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in index 0d532061f..c8be765f0 100644 --- a/lib/awful/rules.lua.in +++ b/lib/awful/rules.lua.in @@ -65,6 +65,8 @@ local rules = {} --

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.

+--

If the value of a property is a function, that function gets called and +-- function's return value is used for the property.

-- --

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