From 2fe9a6dfdf7ac4186436c37c3bb6e935d8f17268 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:01:53 +0200 Subject: [PATCH 1/9] awful.rules: Fix a typo in the docs Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 42c6425b..2232fa85 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -53,7 +53,7 @@ can add: Note that all "rule" entries need to match. If any of the entry does not match, the rule won't be applied. -If a client matches multiple rules, their applied in the order they are +If a client matches multiple rules, they are applied in the order they are 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. From 53bebfde0258c7b4ba575772b39f3999ef0c8e84 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:03:01 +0200 Subject: [PATCH 2/9] awful.rules: Add support for screen names Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 2232fa85..24d0305c 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -9,6 +9,7 @@ -- Grab environment we need local client = client +local screen = screen local table = table local type = type local ipairs = ipairs @@ -35,6 +36,17 @@ If you want to put Firefox on a specific tag at startup, you can add: { rule = { instance = "firefox" }, properties = { tag = mytagobject } } +If you want to put Thunderbird on a specific screen at startup, use: + + { rule = { instance = "Thunderbird" }, + properties = { screen = 1 } } + +Assuming that your X11 server supports the RandR extension, you can also specify +the screen by name: + + { rule = { instance = "Thunderbird" }, + properties = { screen = "VGA1" } } + If you want to put Emacs on a specific tag at startup, and immediately switch to that tag you can add: @@ -197,7 +209,10 @@ function rules.execute(c, props, callbacks) if property ~= "focus" and type(value) == "function" then value = value(c) end - if property == "tag" then + if property == "screen" then + -- Support specifying screens by name ("VGA1") + c.screen = screen[value] + elseif property == "tag" then c.screen = value.screen c:tags({ value }) elseif property == "switchtotag" and value and props.tag then From 7d5e80a8ee95d5f53a0d74bbd3d45d2bc0206a7e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:12:31 +0200 Subject: [PATCH 3/9] Add awful.tag.find_by_name Signed-off-by: Uli Schlachter --- lib/awful/tag.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua index b892f0af..a78a1023 100644 --- a/lib/awful/tag.lua +++ b/lib/awful/tag.lua @@ -420,6 +420,19 @@ function tag.gettags(s) return s and s.tags or {} end +--- Find a tag by name +-- @tparam[opt] screen s The screen of the tag +-- @tparam string name The name of the tag +-- @return The tag found, or `nil` +function tag.find_by_name(s, name) + local tags = s and s.tags or root.tags() + for _, t in ipairs(tags) do + if name == t.name then + return t + end + end +end + --- The tag screen. -- -- **Signal:** From 9cc28a8da54d0edd95efd71feb7f088b04fb6062 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:15:21 +0200 Subject: [PATCH 4/9] awful.rules: Allow specifying tags by name Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 24d0305c..a001e8fc 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -14,6 +14,7 @@ local table = table local type = type local ipairs = ipairs local pairs = pairs +local atag = require("awful.tag") local rules = {} @@ -36,6 +37,11 @@ If you want to put Firefox on a specific tag at startup, you can add: { rule = { instance = "firefox" }, properties = { tag = mytagobject } } +Alternatively, you can specify the tag by name: + + { rule = { instance = "firefox" }, + properties = { tag = "3" } } + If you want to put Thunderbird on a specific screen at startup, use: { rule = { instance = "Thunderbird" }, @@ -213,8 +219,12 @@ function rules.execute(c, props, callbacks) -- Support specifying screens by name ("VGA1") c.screen = screen[value] elseif property == "tag" then - c.screen = value.screen - c:tags({ value }) + local t = value + if type(t) == "string" then + t = atag.find_by_name(props.screen, t) + end + c.screen = t.screen + c:tags({ t }) elseif property == "switchtotag" and value and props.tag then props.tag:view_only() elseif property == "height" or property == "width" or From 65fa565cef0710db0d307392249631f993b11193 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:18:07 +0200 Subject: [PATCH 5/9] Update awful.rules tag-related examples Fixes: https://github.com/awesomeWM/awesome/issues/799 Signed-off-by: Uli Schlachter --- awesomerc.lua | 4 ++-- lib/awful/rules.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/awesomerc.lua b/awesomerc.lua index 6934d522..56f1db83 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -459,9 +459,9 @@ awful.rules.rules = { } }, properties = { floating = true }}, - -- Set Firefox to always map on tags number 2 of screen 1. + -- Set Firefox to always map on the tag named "2" on screen 1. -- { rule = { class = "Firefox" }, - -- properties = { tag = tags[1][2] } }, + -- properties = { screen = 1, tag = "2" } }, } -- }}} diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index a001e8fc..7724050b 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -94,7 +94,7 @@ To match multiple clients with an exception one can couple `rules.except` or { rule_any = { class = { "Pidgin", "Xchat" } }, except_any = { role = { "conversation" } }, - properties = { tag = tags[1][1] } + properties = { tag = "1" } } { rule = {}, From 3f0483003c42c9f566cbc7d470e455fcfc7181da Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:21:37 +0200 Subject: [PATCH 6/9] Default config: Use strings for tag names Tag names really are strings. Numbers just work accidentally since the C code uses luaL_checklstring() to access the tag name and this function silently converts numbers to strings. This also has a nice documentation effect, making it easier for people to figure out that they can change the name of a tag. Plus, with this the changes done by previous commits make more sense (specifying an awful.rules-rule that identifies a tag by name). Signed-off-by: Uli Schlachter --- awesomerc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awesomerc.lua b/awesomerc.lua index 56f1db83..b686e684 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -102,7 +102,7 @@ end tags = {} awful.screen.connect_for_each_screen(function(s) -- Each screen has its own tag table. - tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, awful.layout.layouts[1]) + tags[s] = awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]) end) -- }}} From 9efc5ca40962718d2b48fef11c5782a9efcfc5f7 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:32:16 +0200 Subject: [PATCH 7/9] test-urgent.lua: Test "tag by name" rules With this commit, the code added previously to awful.rules is now also tested. Signed-off-by: Uli Schlachter --- tests/test-urgent.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-urgent.lua b/tests/test-urgent.lua index 1f9706e2..63be5b65 100644 --- a/tests/test-urgent.lua +++ b/tests/test-urgent.lua @@ -35,7 +35,7 @@ local steps = { tags[awful.screen.focused()][1]:view_only() runner.add_to_default_rules({ rule = { class = "XTerm" }, - properties = { tag = tags[awful.screen.focused()][2], focus = true } }) + properties = { tag = "2", focus = true } }) awful.spawn("xterm") end @@ -75,7 +75,7 @@ local steps = { tags[awful.screen.focused()][1]:view_only() runner.add_to_default_rules({ rule = { class = "XTerm" }, - properties = { tag = tags[awful.screen.focused()][2], focus = true, switchtotag = true }}) + properties = { tag = "2", focus = true, switchtotag = true }}) awful.spawn("xterm") @@ -97,7 +97,7 @@ local steps = { manage_cb_done = false runner.add_to_default_rules({rule = { class = "XTerm" }, - properties = { tag = tags[awful.screen.focused()][2], focus = false }}) + properties = { tag = "2", focus = false }}) awful.spawn("xterm") end From fb8c70b07d146dafdadefc81636fd4511fc0135c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Apr 2016 11:32:53 +0200 Subject: [PATCH 8/9] awful.rules: Fix switchtotag with tag names Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 7724050b..f06ee5d5 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -211,6 +211,7 @@ end -- @tab props Properties to apply. -- @tab[opt] callbacks Callbacks to apply. function rules.execute(c, props, callbacks) + local switchtotag = props.switchtotag for property, value in pairs(props) do if property ~= "focus" and type(value) == "function" then value = value(c) @@ -225,14 +226,12 @@ function rules.execute(c, props, callbacks) end c.screen = t.screen c:tags({ t }) - elseif property == "switchtotag" and value and props.tag then - props.tag:view_only() elseif property == "height" or property == "width" or property == "x" or property == "y" then local geo = c:geometry(); geo[property] = value c:geometry(geo); - elseif property == "focus" then + elseif property == "focus" or property == "switchtotag" then -- This will be handled below (function() end)() -- I haven't found a nice way to silence luacheck here elseif type(c[property]) == "function" then @@ -242,6 +241,11 @@ function rules.execute(c, props, callbacks) end end + -- Only do this after the tag has been (possibly) set + if switchtotag and c.first_tag then + c.first_tag:view_only() + end + -- Apply all callbacks. if callbacks then for _, callback in pairs(callbacks) do From 79e16cf950ba15308a2d4f1d5b417f6681a41e30 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 12 Apr 2016 09:33:39 +0200 Subject: [PATCH 9/9] awful.rules.execute: Make for loop easier to read Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index f06ee5d5..d470d8c7 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -211,7 +211,9 @@ end -- @tab props Properties to apply. -- @tab[opt] callbacks Callbacks to apply. function rules.execute(c, props, callbacks) + local handle_later = { focus = true, switchtotag = true } local switchtotag = props.switchtotag + for property, value in pairs(props) do if property ~= "focus" and type(value) == "function" then value = value(c) @@ -231,13 +233,12 @@ function rules.execute(c, props, callbacks) local geo = c:geometry(); geo[property] = value c:geometry(geo); - elseif property == "focus" or property == "switchtotag" then - -- This will be handled below - (function() end)() -- I haven't found a nice way to silence luacheck here - elseif type(c[property]) == "function" then - c[property](c, value) - else - c[property] = value + elseif not handle_later[property] then + if type(c[property]) == "function" then + c[property](c, value) + else + c[property] = value + end end end