Hy, this is a small redesign of the implementation of rules in lib/awful/rules.lua.in. I've removed some hard-coded handling of client properties (i.e. the floating and tag property) and put all poperty set-methods into a list. This list can now be manipulated from rc.lua. IMO this adds some more flexibility in handling client properties.
Regards, Thomas. -- Thomas Brunko [email protected]
From 64846ed14b2331653719750d99f31d60b6856e2e Mon Sep 17 00:00:00 2001 From: Thomas Brunko <[email protected]> Date: Sat, 7 Nov 2009 13:55:18 +0100 Subject: [PATCH] Minor redesign of rules.lua. By putting the methods to set client properties into a table, the user has now the ability to influence how rules act on client properties. From inside the users rc.lua it's now possible to: - Add custom properties with special methods to set them. - Rearrange the order in which properties are set. - Override the way properties are handled. Signed-off-by: Thomas Brunko <[email protected]> --- lib/awful/rules.lua.in | 105 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 87 insertions(+), 18 deletions(-) diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in index 55bcc08..ee6a3ea 100644 --- a/lib/awful/rules.lua.in +++ b/lib/awful/rules.lua.in @@ -15,6 +15,59 @@ local atag = require("awful.tag") --- Apply rules to clients at startup. module("awful.rules") + +--- This table contains the methods to set individual properties. +-- <p>The order of properties in the table defines the order in which +-- they're set on the client. +-- All 'method = nil' properties will be set by using 'client[...] = value'. +-- The method for 'focus' will always be called as the last method. +-- <br/> +-- <code> +-- methods = {<br/> +-- ...<br/> +-- { property = "sticky", method = nil },<br/> +-- { property = "tag", method = function(client,value) awful.client.movetotag(value, client) end},<br/> +-- ...<br/> +-- } +-- </code> +-- +-- @name methods_default +-- @class table + +methods_default = { + { property = "visible", method = nil }, + { property = "floating", method = function(c,v) aclient.floating.set(c,v) end}, + { property = "size_hints_honor", method = nil }, + { property = "maximized", method = function(c,v) c.maximized_horizontal = v ; c.maximized_vertical = v ; end}, + { property = "fullscreen", method = nil }, + { property = "height", method = function(c,v) local geo = c:geometry(); geo["height"] = v ; c:geometry(geo); end}, + { property = "width", method = function(c,v) local geo = c:geometry(); geo["width"] = v ; c:geometry(geo); end}, + { property = "x", method = function(c,v) local geo = c:geometry(); geo["x"] = v ; c:geometry(geo); end}, + { property = "y", method = function(c,v) local geo = c:geometry(); geo["y"] = v ; c:geometry(geo); end}, + { property = "ontop", method = nil }, + { property = "above", method = nil }, + { property = "below", method = nil }, + { property = "normal", method = nil }, + { property = "desktop", method = nil }, + { property = "ignore", method = nil }, + { property = "sticky", method = nil }, + { property = "tag", method = function(c,v) aclient.movetotag(v, c) end}, + { property = "slave", method = function(c,v) aclient.setslave(c) end}, + { property = "screen", method = nil }, + { property = "switchtotag", method = function(c,v) atag.viewonly(props.tag) end}, + { property = "focus", method = function(c,v) if v then client.focus = c end end}, +} + +--- This is the user defined set of methods. +-- <p>A user can create his own methods by copying the variable +-- 'awful.rules.methods_default' into 'awful.rules.methods' and append/insert +-- his own methods. +-- +-- @class table +-- @name methods + +methods = nil + --- This is the global rules table. -- <p>You should fill this table with your rule and properties to apply. -- For example, if you want to set xterm maximized at startup, you can add: @@ -53,10 +106,12 @@ module("awful.rules") -- 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> -- --- @class table -- @name rules +-- @class table + rules = {} + --- Check if a client match a rule. -- @param c The client. -- @param rule The rule to check. @@ -90,28 +145,42 @@ function apply(c) end end - for property, value in pairs(props) do - if property == "floating" then - aclient.floating.set(c, value) - elseif property == "tag" then - aclient.movetotag(value, c) - elseif property == "switchtotag" and value and props.tag then - atag.viewonly(props.tag) - elseif property == "height" or property == "width" or - property == "x" or property == "y" then - local geo = c:geometry(); - geo[property] = value - c:geometry(geo); - elseif type(c[property]) == "function" then - c[property](c, value) + local methods = methods or methods_default + local focus + + -- iterate over all methods and remove the + -- processed ones from 'props'. + for i, a in pairs(methods) do + if a.property ~= "focus" then + if props[a.property] ~= nil then + if a.method then + a.method(c, props[a.property]) + else + c[a.property] = props[a.property] + end + props[a.property] = nil + end else - c[property] = value + focus = a.method end end + + -- iterate over all methods from 'props' not + -- found in our property list + for property, value in pairs(props) do + if property ~= "focus" then + if type(c[property]) == "function" then + c[property](c, value) + else + c[property] = value + end + end + end + -- Do this at last so we do not erase things done by the focus -- signal. - if props.focus then - client.focus = c + if props.focus and focus then + focus(c, props.focus) end end -- 1.6.5.2
