This commit is contained in:
Uli Schlachter 2016-04-15 19:35:23 +02:00
commit bf652914dd
4 changed files with 63 additions and 20 deletions

View File

@ -102,7 +102,7 @@ end
tags = {} tags = {}
awful.screen.connect_for_each_screen(function(s) awful.screen.connect_for_each_screen(function(s)
-- Each screen has its own tag table. -- 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) end)
-- }}} -- }}}
@ -459,9 +459,9 @@ awful.rules.rules = {
} }
}, properties = { floating = true }}, }, 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" }, -- { rule = { class = "Firefox" },
-- properties = { tag = tags[1][2] } }, -- properties = { screen = 1, tag = "2" } },
} }
-- }}} -- }}}

View File

@ -9,10 +9,12 @@
-- Grab environment we need -- Grab environment we need
local client = client local client = client
local screen = screen
local table = table local table = table
local type = type local type = type
local ipairs = ipairs local ipairs = ipairs
local pairs = pairs local pairs = pairs
local atag = require("awful.tag")
local rules = {} local rules = {}
@ -35,6 +37,22 @@ If you want to put Firefox on a specific tag at startup, you can add:
{ rule = { instance = "firefox" }, { rule = { instance = "firefox" },
properties = { tag = mytagobject } } 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" },
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 If you want to put Emacs on a specific tag at startup, and immediately switch
to that tag you can add: to that tag you can add:
@ -53,7 +71,7 @@ can add:
Note that all "rule" entries need to match. If any of the entry does not Note that all "rule" entries need to match. If any of the entry does not
match, the rule won't be applied. 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 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. match function is used to determine if the client matches the rule.
@ -76,7 +94,7 @@ To match multiple clients with an exception one can couple `rules.except` or
{ rule_any = { class = { "Pidgin", "Xchat" } }, { rule_any = { class = { "Pidgin", "Xchat" } },
except_any = { role = { "conversation" } }, except_any = { role = { "conversation" } },
properties = { tag = tags[1][1] } properties = { tag = "1" }
} }
{ rule = {}, { rule = {},
@ -193,30 +211,42 @@ end
-- @tab props Properties to apply. -- @tab props Properties to apply.
-- @tab[opt] callbacks Callbacks to apply. -- @tab[opt] callbacks Callbacks to apply.
function rules.execute(c, props, callbacks) function rules.execute(c, props, callbacks)
local handle_later = { focus = true, switchtotag = true }
local switchtotag = props.switchtotag
for property, value in pairs(props) do for property, value in pairs(props) do
if property ~= "focus" and type(value) == "function" then if property ~= "focus" and type(value) == "function" then
value = value(c) value = value(c)
end end
if property == "tag" then if property == "screen" then
c.screen = value.screen -- Support specifying screens by name ("VGA1")
c:tags({ value }) c.screen = screen[value]
elseif property == "switchtotag" and value and props.tag then elseif property == "tag" then
props.tag:view_only() 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 == "height" or property == "width" or elseif property == "height" or property == "width" or
property == "x" or property == "y" then property == "x" or property == "y" then
local geo = c:geometry(); local geo = c:geometry();
geo[property] = value geo[property] = value
c:geometry(geo); c:geometry(geo);
elseif property == "focus" then elseif not handle_later[property] then
-- This will be handled below if type(c[property]) == "function" then
(function() end)() -- I haven't found a nice way to silence luacheck here c[property](c, value)
elseif type(c[property]) == "function" then else
c[property](c, value) c[property] = value
else end
c[property] = value
end end
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. -- Apply all callbacks.
if callbacks then if callbacks then
for _, callback in pairs(callbacks) do for _, callback in pairs(callbacks) do

View File

@ -420,6 +420,19 @@ function tag.gettags(s)
return s and s.tags or {} return s and s.tags or {}
end 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. --- The tag screen.
-- --
-- **Signal:** -- **Signal:**

View File

@ -35,7 +35,7 @@ local steps = {
tags[awful.screen.focused()][1]:view_only() tags[awful.screen.focused()][1]:view_only()
runner.add_to_default_rules({ rule = { class = "XTerm" }, 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") awful.spawn("xterm")
end end
@ -75,7 +75,7 @@ local steps = {
tags[awful.screen.focused()][1]:view_only() tags[awful.screen.focused()][1]:view_only()
runner.add_to_default_rules({ rule = { class = "XTerm" }, 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") awful.spawn("xterm")
@ -97,7 +97,7 @@ local steps = {
manage_cb_done = false manage_cb_done = false
runner.add_to_default_rules({rule = { class = "XTerm" }, 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") awful.spawn("xterm")
end end