2009-08-24 16:20:11 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local client = client
|
2009-11-08 20:40:38 +01:00
|
|
|
local table = table
|
2009-08-24 16:20:11 +02:00
|
|
|
local type = type
|
|
|
|
local ipairs = ipairs
|
|
|
|
local pairs = pairs
|
|
|
|
local aclient = require("awful.client")
|
2009-08-27 12:43:00 +02:00
|
|
|
local atag = require("awful.tag")
|
2009-08-24 16:20:11 +02:00
|
|
|
|
|
|
|
--- Apply rules to clients at startup.
|
|
|
|
module("awful.rules")
|
|
|
|
|
|
|
|
--- 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:
|
|
|
|
-- <br/>
|
|
|
|
-- <code>
|
|
|
|
-- { rule = { class = "xterm" },
|
|
|
|
-- properties = { maximized_vertical = true, maximized_horizontal = true } }
|
|
|
|
-- </code>
|
|
|
|
-- </p>
|
|
|
|
-- <p>If you want to set mplayer floating at startup, you can add:
|
|
|
|
-- <br/>
|
2009-08-27 12:43:00 +02:00
|
|
|
-- <code>
|
2009-08-24 16:20:11 +02:00
|
|
|
-- { rule = { name = "MPlayer" },
|
|
|
|
-- properties = { floating = true } }
|
|
|
|
-- </code>
|
|
|
|
-- </p>
|
|
|
|
-- <p>If you want to put Firefox on a specific tag at startup, you
|
|
|
|
-- can add:
|
2009-08-27 12:43:00 +02:00
|
|
|
-- <br/>
|
|
|
|
-- <code>
|
|
|
|
-- { rule = { instance = "firefox" }
|
2009-08-24 16:20:11 +02:00
|
|
|
-- properties = { tag = mytagobject } }
|
2009-08-27 12:43:00 +02:00
|
|
|
-- </code>
|
|
|
|
-- </p>
|
|
|
|
-- <p>If you want to put Emacs on a specific tag at startup, and
|
|
|
|
-- immediately switch to that tag you can add:
|
|
|
|
-- <br/>
|
|
|
|
-- <code>
|
|
|
|
-- { rule = { class = "Emacs" }
|
|
|
|
-- properties = { tag = mytagobject, switchtotag = true } }
|
|
|
|
-- </code>
|
|
|
|
-- </p>
|
2009-11-09 19:12:14 +01:00
|
|
|
-- <p>If you want to apply a custom callback to execute when a rule matched,
|
|
|
|
-- for example to pause playing music from mpd when you start dosbox, you
|
2009-11-08 20:40:38 +01:00
|
|
|
-- can add:
|
|
|
|
-- <br/>
|
|
|
|
-- <code>
|
|
|
|
-- { rule = { class = "dosbox" },
|
2009-11-09 19:12:14 +01:00
|
|
|
-- callback = function(c)
|
|
|
|
-- awful.util.spawn('mpc pause')
|
|
|
|
-- end }
|
2009-11-08 20:40:38 +01:00
|
|
|
-- </code>
|
|
|
|
-- </p>
|
2009-08-24 16:20:11 +02:00
|
|
|
-- <p>Note that all "rule" entries need to match. If any of the entry does not
|
|
|
|
-- match, the rule won't be applied.</p>
|
|
|
|
-- <p>If a client matches multiple rules, their applied in the order they are
|
2009-08-24 16:43:00 +02:00
|
|
|
-- 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>
|
2009-08-24 16:20:11 +02:00
|
|
|
--
|
|
|
|
-- @class table
|
|
|
|
-- @name rules
|
|
|
|
rules = {}
|
|
|
|
|
|
|
|
--- Check if a client match a rule.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param rule The rule to check.
|
|
|
|
-- @return True if it matches, false otherwise.
|
|
|
|
function match(c, rule)
|
|
|
|
for field, value in pairs(rule) do
|
2009-08-24 16:43:00 +02:00
|
|
|
if c[field] then
|
2009-08-26 17:49:38 +02:00
|
|
|
if type(c[field]) == "string" then
|
|
|
|
if not c[field]:match(value) and c[field] ~= value then
|
|
|
|
return false
|
|
|
|
end
|
2009-08-24 16:43:00 +02:00
|
|
|
elseif c[field] ~= value then
|
|
|
|
return false
|
|
|
|
end
|
2009-09-03 19:21:59 +02:00
|
|
|
else
|
|
|
|
return false
|
2009-08-24 16:20:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Apply rules to a client.
|
|
|
|
-- @param c The client.
|
|
|
|
function apply(c)
|
2009-10-24 15:05:09 +02:00
|
|
|
local props = {}
|
2009-11-08 20:40:38 +01:00
|
|
|
local callbacks = {}
|
2009-08-24 16:20:11 +02:00
|
|
|
for _, entry in ipairs(rules) do
|
|
|
|
if match(c, entry.rule) then
|
2009-11-09 18:15:06 +01:00
|
|
|
if entry.properties then
|
|
|
|
for property, value in pairs(entry.properties) do
|
|
|
|
props[property] = value
|
|
|
|
end
|
2009-08-25 11:40:35 +02:00
|
|
|
end
|
2009-11-08 20:40:38 +01:00
|
|
|
if entry.callback then
|
|
|
|
table.insert(callbacks, entry.callback)
|
|
|
|
end
|
2009-08-24 16:20:11 +02:00
|
|
|
end
|
|
|
|
end
|
2009-10-24 15:05:09 +02:00
|
|
|
|
|
|
|
for property, value in pairs(props) do
|
|
|
|
if property == "floating" then
|
|
|
|
aclient.floating.set(c, value)
|
|
|
|
elseif property == "tag" then
|
2010-01-08 16:26:21 +01:00
|
|
|
c:tags({ value })
|
2010-01-10 21:30:35 +01:00
|
|
|
c.screen = value.screen
|
2009-10-24 15:05:09 +02:00
|
|
|
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)
|
|
|
|
else
|
|
|
|
c[property] = value
|
|
|
|
end
|
|
|
|
end
|
2009-11-08 20:40:38 +01:00
|
|
|
|
2010-01-08 16:26:21 +01:00
|
|
|
-- If untagged, stick the client on the current one.
|
|
|
|
if #c:tags() == 0 then
|
2010-06-13 09:09:50 +02:00
|
|
|
atag.withcurrent(c)
|
2010-01-08 16:26:21 +01:00
|
|
|
end
|
|
|
|
|
2009-11-08 20:40:38 +01:00
|
|
|
-- Apply all callbacks from matched rules.
|
|
|
|
for i, callback in pairs(callbacks) do
|
|
|
|
callback(c)
|
|
|
|
end
|
|
|
|
|
2009-10-24 15:05:09 +02:00
|
|
|
-- Do this at last so we do not erase things done by the focus
|
|
|
|
-- signal.
|
|
|
|
if props.focus then
|
|
|
|
client.focus = c
|
|
|
|
end
|
2009-08-24 16:20:11 +02:00
|
|
|
end
|
|
|
|
|
2009-10-09 20:39:55 +02:00
|
|
|
client.connect_signal("manage", apply)
|
|
|
|
client.disconnect_signal("manage", atag.withcurrent)
|
2009-08-24 16:20:11 +02:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|