On Sun, Mar 27, 2011 at 11:07 PM, Uli Schlachter <[email protected]> wrote:
> However, you forgot to do the same change in the commit message:
>
>> { rule = { class = "Firefox" },
>> rule_no = { instance = "Navigator" },
>> properties = {floating = true},
>> }
And in the docs too. Bah :P.
> I wonder if it would make sense to explicitly have "except" and "except_any".
> So
> the if would become something like this:
Currently, if you use rule_any, except acts like except_any, and like
except if you use rule.
[...]
> That way, I could e.g. make a rule like this:
>
> - -- Make all clients except <foo> floating:
> { rule = {}, except_any = { class = { "MPlayer", "Nitrogen" } },
> properties = { floating = true } }
So with the current patch, you can would say:
{ rule_any = {}, except = { class = { "MPlayer", "Nitrogen" } },
properties = { floating = true } }
> What do you think?
I considered using except and except_any at first. I thought that it
might be too much, but maybe it actually is better to be explicit and
provide for both except and except_any.
I am attaching two patches:
1. with except, and except_any and more examples in the docs
2. the former, with commit message, and docs fixed
--
Anurag Priyam
http://about.me/yeban/
From a2256a52f1f91e2e0f28e5a7b3f03e90f90a4ba0 Mon Sep 17 00:00:00 2001
From: Anurag Priyam <[email protected]>
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 <[email protected]>
---
lib/awful/rules.lua.in | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in
index 1b1c390..20def2d 100644
--- a/lib/awful/rules.lua.in
+++ b/lib/awful/rules.lua.in
@@ -74,6 +74,30 @@ module("awful.rules")
-- </code>
-- </p>
--
+-- <p> To match multiple clients with an exception one can couple 'except' or
+-- 'except_any' with the rules:
+-- <br/>
+-- <code>
+-- { rule = { class = "Firefox" },
+-- except = { instance = "Navigator" },
+-- properties = {floating = true},
+-- },
+-- </code>
+-- <br/>
+-- <code>
+-- { rule_any = { class = { "Pidgin", "Xchat" } },
+-- except_any = { role = { "conversation" } },
+-- properties = { tag = tags[1][1] }
+-- }
+-- <br/>
+-- <code>
+-- { rule = {},
+-- except_any = { class = { "Firefox", "Vim" } },
+-- properties = { floating = true }
+-- }
+-- </code>
+-- </p>
+--
-- @class table
-- @name rules
rules = {}
@@ -83,6 +107,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
@@ -104,6 +129,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
@@ -124,8 +150,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
--
1.7.4.1
From 4912f5371f332cc2f01f3faac7dfbba69e6abb3b Mon Sep 17 00:00:00 2001
From: Anurag Priyam <[email protected]>
Date: Sun, 27 Mar 2011 20:52:50 +0530
Subject: [PATCH] rules: allow defining exceptions to a rule - except
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},
}
Signed-off-by: Anurag Priyam <[email protected]>
---
lib/awful/rules.lua.in | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/awful/rules.lua.in b/lib/awful/rules.lua.in
index 1b1c390..1bd6c4f 100644
--- a/lib/awful/rules.lua.in
+++ b/lib/awful/rules.lua.in
@@ -74,6 +74,17 @@ module("awful.rules")
-- </code>
-- </p>
--
+-- <p> To match multiple clients with an exception one can couple 'except' with
+-- either 'rule' or 'rule_any', using the same semantics:
+-- <br/>
+-- <code>
+-- { rule = { class = "Firefox" },
+-- except = { instance = "Navigator" },
+-- properties = {floating = true},
+-- },
+-- </code>
+-- </p>
+--
-- @class table
-- @name rules
rules = {}
@@ -83,6 +94,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
@@ -104,6 +116,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
@@ -124,8 +137,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) and not match(c, entry.except)) or
+ (match_any(c, entry.rule_any) and not match_any(c, entry.except)) then
if entry.properties then
for property, value in pairs(entry.properties) do
props[property] = value
--
1.7.4.1