]> git.lizzy.rs Git - bspwm.git/commitdiff
Enhance external rules example scripts
authorBastien Dejean <nihilhill@gmail.com>
Sat, 16 Nov 2013 11:34:22 +0000 (12:34 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Sat, 16 Nov 2013 11:34:22 +0000 (12:34 +0100)
contrib/rule_scripts/README.asciidoc [deleted file]
contrib/rule_scripts/rulc [deleted file]
contrib/rule_scripts/ruld [deleted file]
contrib/rule_scripts/rule_command [deleted file]
examples/bspwmrc
examples/external_rules/README.asciidoc [new file with mode: 0644]
examples/external_rules/bspwm_rules [new file with mode: 0755]
examples/external_rules/bspwmrc [new file with mode: 0755]
examples/external_rules/rulc [new file with mode: 0755]
examples/external_rules/ruld [new file with mode: 0755]
examples/external_rules/rule_command [new file with mode: 0755]

diff --git a/contrib/rule_scripts/README.asciidoc b/contrib/rule_scripts/README.asciidoc
deleted file mode 100644 (file)
index 17ae1cf..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-Synopsis
---------
-
-Server
-~~~~~~
-
-*ruld* [*-h*|*-p* 'PORT']
-
-Client
-~~~~~~
-
-*rulc* [*-h*|*-p* 'PORT'|*-a*|*-r*|*-l*|*-t*|*-q*] 'DATA' ...
-
-Options
--------
-
-Shared
-~~~~~~
-
-*-h*::
-    Print the synopsis and exit.
-
-*-p* 'PORT'::
-    Set the socket port.
-
-Client
-~~~~~~
-
-*-a* 'HYPOT' 'CONSEQ' ['[duration=DURATION][,delay=DELAY]']::
-    Create a new rule. 'HYPOT' is a Lua expression that represent the rule hypothesis and involves the following strings: 'class', 'instance', 'title', 'type' and 'state'.
-
-*-r* 'STRING'|head|tail::
-    Remove the rules containing 'STRING' in their hypothesis or remove the first or last rule.
-
-*-l*::
-    List the rules.
-
-*-t* 'CLASS' 'INSTANCE' 'TITLE' 'TYPE' 'STATE'::
-    Test the rules for the given window informations.
-
-*-q*::
-    Kill the server.
diff --git a/contrib/rule_scripts/rulc b/contrib/rule_scripts/rulc
deleted file mode 100755 (executable)
index f0cd633..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#! /usr/bin/env lua
-
-local p = require "posix"
-local port = 54321
-
-local short = "hp:arltq"
-local long = {
-    {"help", "none", 'h'},
-    {"port", "required", 'p'},
-    {"add", "none", 'a'},
-    {"remove", "none", 'r'},
-    {"list", "none", 'l'},
-    {"test", "none", 't'},
-    {"quit", "none", 'q'}
-}
-
-local cmd_assoc = {
-    a = "add",
-    r = "remove",
-    l = "list",
-    t = "test",
-    q = "quit"
-}
-
-local cmd
-local data_idx = 1
-for opt, optarg, optind, longind in p.getopt(arg, short, long) do
-    if opt == '?' then
-        print("Unrecognized option")
-        os.exit(1)
-    elseif opt == 'h' then
-        print("Usage: rulc [-h|-p PORT|-a|-r|-l|-t|-q] DATA ...")
-        os.exit(0)
-    elseif opt == 'p' then
-        port = optarg
-    else
-        cmd = cmd_assoc[opt]
-    end
-    data_idx = optind
-end
-
-if not cmd then
-    os.exit(1)
-end
-
-local msg = cmd
-if cmd == "test" then
-    msg = string.format("%s {class=%q, instance=%q, title=%q, type=%q, state=%q}", msg, arg[data_idx], arg[data_idx+1], arg[data_idx+2], arg[data_idx+3], arg[data_idx+4])
-elseif cmd == "add" then
-    msg = string.format("%s {%q, %q, %s}", msg, arg[data_idx], arg[data_idx+1], arg[data_idx+2] and string.format("{%s}", arg[data_idx+2]) or "")
-elseif cmd == "remove" then
-    msg = string.format("%s %s", msg, arg[data_idx])
-end
-
-local fd = p.socket(p.AF_INET, p.SOCK_STREAM, 0)
-local s = p.connect(fd, {family=p.AF_INET, addr="127.0.0.1", port=port})
-if not s then
-    p.close(fd)
-    os.exit(1)
-end
-p.send(fd, msg)
-rsp = p.recv(fd, p.BUFSIZ)
-
-if rsp and #rsp > 0 then
-    print(rsp)
-end
-
-p.close(fd)
diff --git a/contrib/rule_scripts/ruld b/contrib/rule_scripts/ruld
deleted file mode 100755 (executable)
index e4a8674..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-#! /usr/bin/env lua
-
-local p = require("posix")
-local port = 54321
-
-local short = "hp:"
-local long = {
-    {"help", "none", 'h'},
-    {"port", "required", 'p'},
-}
-
-local rules = {}
-
-for opt, optarg, optind, longind in p.getopt(arg, short, long) do
-    if opt == '?' then
-        print("Unrecognized option")
-        os.exit(1)
-    elseif opt == 'h' then
-        print("Usage: ruld [-h|-p PORT]")
-        os.exit(0)
-    elseif opt == 'p' then
-        port = optarg
-    end
-end
-
-function eval(exp, env)
-    local f
-    local value = "return " .. exp
-    if env then
-        f = load(value, nil, nil, env)
-    else
-        f = load(value)
-    end
-    return f and f()
-end
-
-function test(env)
-    local rsp = ""
-    for index = #rules, 1, -1 do
-        local entry = rules[index]
-        if eval(entry[1], env) then
-            local delay, duration
-            if entry[3] then
-                delay = entry[3].delay
-                duration = entry[3].duration
-                if delay and delay > 0 then
-                    entry[3].delay = delay - 1
-                end
-                if ((not delay) or delay == 0) and duration and duration > 0 then
-                    entry[3].duration = duration - 1
-                end
-            end
-            if (((not delay) or delay == 0) and ((not duration) or duration > 0)) then
-                if #rsp > 0 then
-                    rsp = rsp .. " " .. entry[2]
-                else
-                    rsp = entry[2]
-                end
-            end
-            if duration and duration <= 1 then
-                table.remove(rules, index)
-            end
-        end
-    end
-    return rsp
-end
-
-local fd = p.socket(p.AF_INET, p.SOCK_STREAM, 0)
-p.setsockopt(fd, p.SOL_SOCKET, p.SO_REUSEADDR, 1)
-p.bind(fd, {family=p.AF_INET, addr="127.0.0.1", port=port})
-p.listen(fd, p.SOMAXCONN)
-local running = true
-
-while running do
-    ret_fd = p.accept(fd)
-    if ret_fd then
-        local msg = p.recv(ret_fd, p.BUFSIZ)
-        if msg then
-            local cmd, data = nil
-            sep = msg:find(" ")
-            if sep then
-                cmd = msg:sub(1, sep - 1)
-                data = msg:sub(sep + 1)
-            else
-                cmd = msg
-            end
-            if cmd == "test" then
-                local env = eval(data)
-                if env then
-                    rsp = test(env)
-                    p.send(ret_fd, rsp)
-                end
-            elseif cmd == "add" then
-                local value = eval(data)
-                if value then
-                    table.insert(rules, value)
-                end
-            elseif cmd == "remove" then
-                if data == "tail" then
-                    table.remove(rules, #rules)
-                elseif data == "head" then
-                    table.remove(rules, 1)
-                else
-                    for index = #rules, 1, -1 do
-                        if rules[index][1]:find(data) then
-                            table.remove(rules, index)
-                        end
-                    end
-                end
-            elseif cmd == "quit" then
-                running = false
-            elseif cmd == "list" then
-                local rsp = ""
-                for index, entry in pairs(rules) do
-                    rsp = rsp .. string.format("%s => %s", entry[1], entry[2])
-                    if entry[3] then
-                        if entry[3].delay then
-                            rsp = rsp .. string.format(" @%i", entry[3].delay)
-                        end
-                        if entry[3].duration then
-                            rsp = rsp .. string.format(" +%i", entry[3].duration)
-                        end
-                    end
-                    if index < #rules then
-                        rsp = rsp .. "\n"
-                    end
-                end
-                p.send(ret_fd, rsp)
-            end
-        end
-        p.close(ret_fd)
-    end
-end
-
-p.close(fd)
diff --git a/contrib/rule_scripts/rule_command b/contrib/rule_scripts/rule_command
deleted file mode 100755 (executable)
index c1318cb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-
-xwinfo -cints $1 | xargs -d '\n' rulc -t
index b3871be7935874515e897be99658a57a9ecc5ee9..36500b22eaa18f367f639e704de0529758ba8289 100755 (executable)
@@ -7,11 +7,3 @@ bspc config window_gap          12
 bspc config split_ratio         0.52
 bspc config borderless_monocle  true
 bspc config gapless_monocle     true
-
-bspc config rule_command "$(which rule_command)"
-
-rulc -a 'class=="Gimp"' 'desktop=^8, follow=on, floating=on'
-rulc -a 'class=="Chromium"' 'desktop=^2'
-rulc -a 'instance=="mpv"' 'floating=on'
-rulc -a 'class=="Kupfer.py"' 'focus=on'
-rulc -a 'class=="Screenkey"' 'manage=off'
diff --git a/examples/external_rules/README.asciidoc b/examples/external_rules/README.asciidoc
new file mode 100644 (file)
index 0000000..17ae1cf
--- /dev/null
@@ -0,0 +1,42 @@
+Synopsis
+--------
+
+Server
+~~~~~~
+
+*ruld* [*-h*|*-p* 'PORT']
+
+Client
+~~~~~~
+
+*rulc* [*-h*|*-p* 'PORT'|*-a*|*-r*|*-l*|*-t*|*-q*] 'DATA' ...
+
+Options
+-------
+
+Shared
+~~~~~~
+
+*-h*::
+    Print the synopsis and exit.
+
+*-p* 'PORT'::
+    Set the socket port.
+
+Client
+~~~~~~
+
+*-a* 'HYPOT' 'CONSEQ' ['[duration=DURATION][,delay=DELAY]']::
+    Create a new rule. 'HYPOT' is a Lua expression that represent the rule hypothesis and involves the following strings: 'class', 'instance', 'title', 'type' and 'state'.
+
+*-r* 'STRING'|head|tail::
+    Remove the rules containing 'STRING' in their hypothesis or remove the first or last rule.
+
+*-l*::
+    List the rules.
+
+*-t* 'CLASS' 'INSTANCE' 'TITLE' 'TYPE' 'STATE'::
+    Test the rules for the given window informations.
+
+*-q*::
+    Kill the server.
diff --git a/examples/external_rules/bspwm_rules b/examples/external_rules/bspwm_rules
new file mode 100755 (executable)
index 0000000..6e91732
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+if ! rulc -l > /dev/null ; then
+    (setsid ruld &)
+    while ! rulc -l > /dev/null ; do
+        sleep 0.1
+    done
+fi
+rules=$(rulc -l)
+if [ -z "$rules" ] ; then
+    rulc -a 'class=="Gimp"' 'desktop=^8, follow=on, floating=on'
+    rulc -a 'class=="Chromium"' 'desktop=^2'
+    rulc -a 'instance=="mpv"' 'floating=on'
+    rulc -a 'class=="Kupfer.py"' 'focus=on'
+    rulc -a 'class=="Screenkey"' 'manage=off'
+fi
diff --git a/examples/external_rules/bspwmrc b/examples/external_rules/bspwmrc
new file mode 100755 (executable)
index 0000000..5ce0369
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+bspc config rule_command "$(which rule_command)"
+bspwm_rules
diff --git a/examples/external_rules/rulc b/examples/external_rules/rulc
new file mode 100755 (executable)
index 0000000..f0cd633
--- /dev/null
@@ -0,0 +1,68 @@
+#! /usr/bin/env lua
+
+local p = require "posix"
+local port = 54321
+
+local short = "hp:arltq"
+local long = {
+    {"help", "none", 'h'},
+    {"port", "required", 'p'},
+    {"add", "none", 'a'},
+    {"remove", "none", 'r'},
+    {"list", "none", 'l'},
+    {"test", "none", 't'},
+    {"quit", "none", 'q'}
+}
+
+local cmd_assoc = {
+    a = "add",
+    r = "remove",
+    l = "list",
+    t = "test",
+    q = "quit"
+}
+
+local cmd
+local data_idx = 1
+for opt, optarg, optind, longind in p.getopt(arg, short, long) do
+    if opt == '?' then
+        print("Unrecognized option")
+        os.exit(1)
+    elseif opt == 'h' then
+        print("Usage: rulc [-h|-p PORT|-a|-r|-l|-t|-q] DATA ...")
+        os.exit(0)
+    elseif opt == 'p' then
+        port = optarg
+    else
+        cmd = cmd_assoc[opt]
+    end
+    data_idx = optind
+end
+
+if not cmd then
+    os.exit(1)
+end
+
+local msg = cmd
+if cmd == "test" then
+    msg = string.format("%s {class=%q, instance=%q, title=%q, type=%q, state=%q}", msg, arg[data_idx], arg[data_idx+1], arg[data_idx+2], arg[data_idx+3], arg[data_idx+4])
+elseif cmd == "add" then
+    msg = string.format("%s {%q, %q, %s}", msg, arg[data_idx], arg[data_idx+1], arg[data_idx+2] and string.format("{%s}", arg[data_idx+2]) or "")
+elseif cmd == "remove" then
+    msg = string.format("%s %s", msg, arg[data_idx])
+end
+
+local fd = p.socket(p.AF_INET, p.SOCK_STREAM, 0)
+local s = p.connect(fd, {family=p.AF_INET, addr="127.0.0.1", port=port})
+if not s then
+    p.close(fd)
+    os.exit(1)
+end
+p.send(fd, msg)
+rsp = p.recv(fd, p.BUFSIZ)
+
+if rsp and #rsp > 0 then
+    print(rsp)
+end
+
+p.close(fd)
diff --git a/examples/external_rules/ruld b/examples/external_rules/ruld
new file mode 100755 (executable)
index 0000000..e4a8674
--- /dev/null
@@ -0,0 +1,135 @@
+#! /usr/bin/env lua
+
+local p = require("posix")
+local port = 54321
+
+local short = "hp:"
+local long = {
+    {"help", "none", 'h'},
+    {"port", "required", 'p'},
+}
+
+local rules = {}
+
+for opt, optarg, optind, longind in p.getopt(arg, short, long) do
+    if opt == '?' then
+        print("Unrecognized option")
+        os.exit(1)
+    elseif opt == 'h' then
+        print("Usage: ruld [-h|-p PORT]")
+        os.exit(0)
+    elseif opt == 'p' then
+        port = optarg
+    end
+end
+
+function eval(exp, env)
+    local f
+    local value = "return " .. exp
+    if env then
+        f = load(value, nil, nil, env)
+    else
+        f = load(value)
+    end
+    return f and f()
+end
+
+function test(env)
+    local rsp = ""
+    for index = #rules, 1, -1 do
+        local entry = rules[index]
+        if eval(entry[1], env) then
+            local delay, duration
+            if entry[3] then
+                delay = entry[3].delay
+                duration = entry[3].duration
+                if delay and delay > 0 then
+                    entry[3].delay = delay - 1
+                end
+                if ((not delay) or delay == 0) and duration and duration > 0 then
+                    entry[3].duration = duration - 1
+                end
+            end
+            if (((not delay) or delay == 0) and ((not duration) or duration > 0)) then
+                if #rsp > 0 then
+                    rsp = rsp .. " " .. entry[2]
+                else
+                    rsp = entry[2]
+                end
+            end
+            if duration and duration <= 1 then
+                table.remove(rules, index)
+            end
+        end
+    end
+    return rsp
+end
+
+local fd = p.socket(p.AF_INET, p.SOCK_STREAM, 0)
+p.setsockopt(fd, p.SOL_SOCKET, p.SO_REUSEADDR, 1)
+p.bind(fd, {family=p.AF_INET, addr="127.0.0.1", port=port})
+p.listen(fd, p.SOMAXCONN)
+local running = true
+
+while running do
+    ret_fd = p.accept(fd)
+    if ret_fd then
+        local msg = p.recv(ret_fd, p.BUFSIZ)
+        if msg then
+            local cmd, data = nil
+            sep = msg:find(" ")
+            if sep then
+                cmd = msg:sub(1, sep - 1)
+                data = msg:sub(sep + 1)
+            else
+                cmd = msg
+            end
+            if cmd == "test" then
+                local env = eval(data)
+                if env then
+                    rsp = test(env)
+                    p.send(ret_fd, rsp)
+                end
+            elseif cmd == "add" then
+                local value = eval(data)
+                if value then
+                    table.insert(rules, value)
+                end
+            elseif cmd == "remove" then
+                if data == "tail" then
+                    table.remove(rules, #rules)
+                elseif data == "head" then
+                    table.remove(rules, 1)
+                else
+                    for index = #rules, 1, -1 do
+                        if rules[index][1]:find(data) then
+                            table.remove(rules, index)
+                        end
+                    end
+                end
+            elseif cmd == "quit" then
+                running = false
+            elseif cmd == "list" then
+                local rsp = ""
+                for index, entry in pairs(rules) do
+                    rsp = rsp .. string.format("%s => %s", entry[1], entry[2])
+                    if entry[3] then
+                        if entry[3].delay then
+                            rsp = rsp .. string.format(" @%i", entry[3].delay)
+                        end
+                        if entry[3].duration then
+                            rsp = rsp .. string.format(" +%i", entry[3].duration)
+                        end
+                    end
+                    if index < #rules then
+                        rsp = rsp .. "\n"
+                    end
+                end
+                p.send(ret_fd, rsp)
+            end
+        end
+        p.close(ret_fd)
+    end
+end
+
+p.close(fd)
diff --git a/examples/external_rules/rule_command b/examples/external_rules/rule_command
new file mode 100755 (executable)
index 0000000..c1318cb
--- /dev/null
@@ -0,0 +1,3 @@
+#! /bin/sh
+
+xwinfo -cints $1 | xargs -d '\n' rulc -t