1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
12 local aclient
= require("awful.client")
13 local atag
= require("awful.tag")
15 --- Apply rules to clients at startup.
18 --- This is the global rules table.
19 -- <p>You should fill this table with your rule and properties to apply.
20 -- For example, if you want to set xterm maximized at startup, you can add:
23 -- { rule = { class = "xterm" },
24 -- properties = { maximized_vertical = true, maximized_horizontal = true } }
27 -- <p>If you want to set mplayer floating at startup, you can add:
30 -- { rule = { name = "MPlayer" },
31 -- properties = { floating = true } }
34 -- <p>If you want to put Firefox on a specific tag at startup, you
38 -- { rule = { instance = "firefox" }
39 -- properties = { tag = mytagobject } }
42 -- <p>If you want to put Emacs on a specific tag at startup, and
43 -- immediately switch to that tag you can add:
46 -- { rule = { class = "Emacs" }
47 -- properties = { tag = mytagobject, switchtotag = true } }
50 -- <p>Note that all "rule" entries need to match. If any of the entry does not
51 -- match, the rule won't be applied.</p>
52 -- <p>If a client matches multiple rules, their applied in the order they are
53 -- put in this global rules table. If the value of a rule is a string, then the
54 -- match function is used to determine if the client matches the rule.</p>
60 --- Check if a client match a rule.
61 -- @param c The client.
62 -- @param rule The rule to check.
63 -- @return True if it matches, false otherwise.
64 function match(c
, rule
)
65 for field
, value
in pairs(rule
) do
67 if type(c
[field
]) == "string" then
68 if not c
[field
]:match(value
) and c
[field
] ~= value
then
71 elseif c
[field
] ~= value
then
81 --- Apply rules to a client.
82 -- @param c The client.
84 for _
, entry
in ipairs(rules
) do
85 if match(c
, entry
.rule
) then
86 for property
, value
in pairs(entry
.properties
) do
87 if property
== "floating" then
88 aclient
.floating
.set(c
, value
)
89 elseif property
== "tag" then
90 aclient
.movetotag(value
, c
)
91 elseif property
== "switchtotag" and value
92 and entry
.properties
["tag"] then
93 atag
.viewonly(entry
.properties
["tag"])
94 elseif property
== "height" or property
== "width" or
95 property
== "x" or property
== "y" then
96 local geo
= c
:geometry();
99 elseif type(c
[property
]) == "function" then
100 c
[property
](c
, value
)
105 -- Do this at last so we do not erase things done by the focus
107 if entry
.properties
.focus
then
114 client
.add_signal("manage", apply
)
116 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80