On Sun, Mar 27, 2011 at 8:15 PM, Uli Schlachter <[email protected]> wrote:
[...]
> Could you please test patches before sending them? Thanks.
> And don't tell me you did test this, because to make it break you just have to

I am so sorry. Attached a new patch.

[...]
> This will happen on every rule which doesn't specify a rule_no, because of 
> this
> code (match is called with 'nil' as its second argument):
>
> if  (entry.rule and match(c, entry.rule) and not match(c, entry.rule_no)) or
>
> The first thing that match() does is calling pairs() on its second argument 
> and
> pairs(nil) results in the lua error I pasted above.

Yeah.

I monkey patched match, and match_any a bit to avoid the error (and a
lot of repetition in apply). I hope its ok.

> Now for the actual name: Why "rule_no"? What is a "rule_number"? :-P

It was meant to be a 'no' (like, yes, or no) :P.

> I'd propose a name which actually explains what this does, e.g. "except",
> "ignore", "skip".

Changed to 'except'.

-- 
Anurag Priyam
http://about.me/yeban/
From 0bb0ad5ec7f778a2903383706583ba2673866dfd 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

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" },
 rule_no = { 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..fcb1ed8 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 'rule_no' 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

Reply via email to