From 55f5ba6911ff6fd7fee200fb719c701c02f71870 Mon Sep 17 00:00:00 2001
From: Anurag Priyam
Date: Sun, 27 Mar 2011 20:52:50 +0530
Subject: [PATCH] rules: allow defining exceptions to a rule - except, and
except_any
So you want to make all Firefox windows floating except the main window
(instance = Navigator). You can either list all possible windows in
rules and make them floating, or make all of them floating except one:
{ rule = { class = "Firefox" },
except = { instance = "Navigator" },
properties = {floating = true},
}
More examples in the docs.
Signed-off-by: Anurag Priyam
Signed-off-by: Uli Schlachter
---
lib/awful/rules.lua.in | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in
index 5e942660..9c41f943 100644
--- a/lib/awful/rules.lua.in
+++ b/lib/awful/rules.lua.in
@@ -71,6 +71,30 @@ module("awful.rules")
--
--
--
+-- To match multiple clients with an exception one can couple 'except' or
+-- 'except_any' with the rules:
+--
+--
+-- { rule = { class = "Firefox" },
+-- except = { instance = "Navigator" },
+-- properties = {floating = true},
+-- },
+--
+--
+--
+-- { rule_any = { class = { "Pidgin", "Xchat" } },
+-- except_any = { role = { "conversation" } },
+-- properties = { tag = tags[1][1] }
+-- }
+--
+--
+-- { rule = {},
+-- except_any = { class = { "Firefox", "Vim" } },
+-- properties = { floating = true }
+-- }
+--
+--
+--
-- @class table
-- @name rules
rules = {}
@@ -80,6 +104,7 @@ rules = {}
-- @param rule The rule to check.
-- @return True if it matches, false otherwise.
function match(c, rule)
+ if not rule then return false end
for field, value in pairs(rule) do
if c[field] then
if type(c[field]) == "string" then
@@ -101,6 +126,7 @@ end
-- @param rules The rule to check.
-- @return True if at least one rule is matched, false otherwise.
function match_any(c, rule)
+ if not rule then return false end
for field, values in pairs(rule) do
if c[field] then
for _, value in ipairs(values) do
@@ -121,8 +147,8 @@ function apply(c)
local props = {}
local callbacks = {}
for _, entry in ipairs(rules) do
- if (entry.rule and match(c, entry.rule)) or
- (entry.rule_any and match_any(c, entry.rule_any)) then
+ if (match(c, entry.rule) or match_any(c, entry.rule_any)) and
+ (not match(c, entry.except) and not match_any(c, entry.except_any)) then
if entry.properties then
for property, value in pairs(entry.properties) do
props[property] = value