Merge pull request #4 from smartass101/dynamic_tags

Support dynamic tags (adding/deleting) and extra tag props
This commit is contained in:
Albert Diserholt 2019-01-07 19:52:06 +01:00 committed by GitHub
commit 32d878d0d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 13 deletions

View File

@ -53,6 +53,28 @@ local function salvage(tag)
capi.screen[newscreen]:emit_signal("tag::history::update")
end
--- Create one new tag with sharedtags metadata.
-- This is mostly useful for setups with dynamic tag adding.
-- @tparam number i The tag (global/shared) index
-- @tparam table t The tag definition table for awful.tag.add
-- @treturn table The created tag.
function sharedtags.add(i, t)
t = awful.util.table.clone(t, false) -- shallow copy for modification
t.screen = (t.screen and t.screen <= capi.screen.count()) and t.screen or capi.screen.primary
t.sharedtagindex = i
local tag = awful.tag.add(t.name or i, t)
-- If no tag is selected for this screen, then select this one.
if not tag.screen.selected_tag then
tag:view_only() -- Updates the history as well.
end
-- Make sure to salvage the tag in case the screen disappears.
tag:connect_signal("request::screen", salvage)
return tag
end
--- Create new tag objects.
-- The first tag defined for each screen will be automatically selected.
-- @tparam table def A list of tables with the optional keys `name`, `layout`
@ -76,24 +98,12 @@ function sharedtags.new(def)
local tags = {}
for i,t in ipairs(def) do
tags[i] = awful.tag.add(t.name or i, {
screen = (t.screen and t.screen <= capi.screen.count()) and t.screen or capi.screen.primary,
layout = t.layout,
sharedtagindex = i
})
tags[i] = sharedtags.add(i, t)
-- Create an alias between the index and the name.
if t.name and type(t.name) ~= "number" then
tags[t.name] = tags[i]
end
-- If no tag is selected for this screen, then select this one.
if not tags[i].screen.selected_tag then
tags[i]:view_only() -- Updates the history as well.
end
-- Make sure to salvage the tag in case the screen disappears.
tags[i]:connect_signal("request::screen", salvage)
end
return tags