From 498e61a00aaf6a8661e72345c579427b617464ed Mon Sep 17 00:00:00 2001 From: Ondrej Grover Date: Sun, 6 Jan 2019 13:04:33 +0100 Subject: [PATCH 1/2] refactor single tag addition into sharedtags.add This is mostly useful for dynamic tag adding/deleting. --- init.lua | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index ef39655..147e4bd 100644 --- a/init.lua +++ b/init.lua @@ -53,6 +53,29 @@ 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) + local tag = 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 + }) + + -- 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 +99,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 From cc6e1789b936ae7dd508d6aea461b8d2f63508ab Mon Sep 17 00:00:00 2001 From: Ondrej Grover Date: Sun, 6 Jan 2019 16:02:12 +0100 Subject: [PATCH 2/2] pass all tag properties to awful.tag.add Previously only name, screen and layout was passed, eveything else was silently discarded. --- init.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 147e4bd..b731f35 100644 --- a/init.lua +++ b/init.lua @@ -59,11 +59,10 @@ end -- @tparam table t The tag definition table for awful.tag.add -- @treturn table The created tag. function sharedtags.add(i, t) - local tag = 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 - }) + 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