1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
13 local aclient
= require("awful.client")
14 local atag
= require("awful.tag")
16 --- Apply rules to clients at startup.
19 --- This is the global rules table.
20 -- <p>You should fill this table with your rule and properties to apply.
21 -- For example, if you want to set xterm maximized at startup, you can add:
24 -- { rule = { class = "xterm" },
25 -- properties = { maximized_vertical = true, maximized_horizontal = true } }
28 -- <p>If you want to set mplayer floating at startup, you can add:
31 -- { rule = { name = "MPlayer" },
32 -- properties = { floating = true } }
35 -- <p>If you want to put Firefox on a specific tag at startup, you
39 -- { rule = { instance = "firefox" },
40 -- properties = { tag = mytagobject } }
43 -- <p>If you want to put Emacs on a specific tag at startup, and
44 -- immediately switch to that tag you can add:
47 -- { rule = { class = "Emacs" },
48 -- properties = { tag = mytagobject, switchtotag = true } }
51 -- <p>If you want to apply a custom callback to execute when a rule matched, you
55 -- { rule = { class = "dosbox" },
56 -- callback = awful.placement.centered }
59 -- <p>Note that all "rule" entries need to match. If any of the entry does not
60 -- match, the rule won't be applied.</p>
61 -- <p>If a client matches multiple rules, their applied in the order they are
62 -- put in this global rules table. If the value of a rule is a string, then the
63 -- match function is used to determine if the client matches the rule.</p>
65 -- <p> To match multiple clients to a rule one need to use slightly different
69 -- { rule_any = { class = { "MPlayer", "Nitrogen" }, instance = { "xterm" } },
70 -- properties = { floating = true } }
74 -- <p> To match multiple clients with an exception one can couple 'except' or
75 -- 'except_any' with the rules:
78 -- { rule = { class = "Firefox" },
79 -- except = { instance = "Navigator" },
80 -- properties = {floating = true},
85 -- { rule_any = { class = { "Pidgin", "Xchat" } },
86 -- except_any = { role = { "conversation" } },
87 -- properties = { tag = tags[1][1] }
92 -- except_any = { class = { "Firefox", "Vim" } },
93 -- properties = { floating = true }
102 --- Check if a client match a rule.
103 -- @param c The client.
104 -- @param rule The rule to check.
105 -- @return True if it matches, false otherwise.
106 function match(c
, rule
)
107 if not rule
then return false end
108 for field
, value
in pairs(rule
) do
110 if type(c
[field
]) == "string" then
111 if not c
[field
]:match(value
) and c
[field
] ~= value
then
114 elseif c
[field
] ~= value
then
124 --- Check if a client match a rule. Multiple clients can be matched
125 -- @param c The client.
126 -- @param rules The rule to check.
127 -- @return True if at least one rule is matched, false otherwise.
128 function match_any(c
, rule
)
129 if not rule
then return false end
130 for field
, values
in pairs(rule
) do
132 for _
, value
in ipairs(values
) do
133 if c
[field
] == value
then
135 elseif type(c
[field
]) == "string" and c
[field
]:match(value
) then
144 --- Apply rules to a client.
145 -- @param c The client.
149 for _
, entry
in ipairs(rules
) do
150 if (match(c
, entry
.rule
) or match_any(c
, entry
.rule_any
)) and
151 (not match(c
, entry
.except
) and not match_any(c
, entry
.except_any
)) then
152 if entry
.properties
then
153 for property
, value
in pairs(entry
.properties
) do
154 props
[property
] = value
157 if entry
.callback
then
158 table.insert(callbacks
, entry
.callback
)
163 for property
, value
in pairs(props
) do
164 if property
== "floating" then
165 aclient
.floating
.set(c
, value
)
166 elseif property
== "tag" then
168 c
.screen
= value
.screen
169 elseif property
== "switchtotag" and value
and props
.tag then
170 atag
.viewonly(props
.tag)
171 elseif property
== "height" or property
== "width" or
172 property
== "x" or property
== "y" then
173 local geo
= c
:geometry();
174 geo
[property
] = value
176 elseif type(c
[property
]) == "function" then
177 c
[property
](c
, value
)
183 -- If untagged, stick the client on the current one.
184 if #c
:tags() == 0 then
188 -- Apply all callbacks from matched rules.
189 for i
, callback
in pairs(callbacks
) do
193 -- Do this at last so we do not erase things done by the focus
200 client
.add_signal("manage", apply
)
201 client
.remove_signal("manage", atag
.withcurrent
)
203 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80