tag.delete(t, fb):
    If there are > 0 clients and only 1 tag, then don't delete the tag.

    Delete a tag 't' if there are no clients exclusively assigned to it.

Signed-off-by: Perry Hargrave <[email protected]>
---
 lib/awful/tag.lua.in |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in
index 9f229de..429a56d 100644
--- a/lib/awful/tag.lua.in
+++ b/lib/awful/tag.lua.in
@@ -48,6 +48,40 @@ function add(name, props)
     return newtag
 end
 
+--- Delete a tag.
+-- @param target_tag Optional tag object to delete, [tag.selected()]
+-- @param fallback_tag Tag to assign stickied tags to. [screen[]:tags()[1]]
+-- If there are no clients exclusively on this tag then delete it.
+function delete(target_tag, fallback_tag)
+    -- abort if no tag is passed or currently selected
+    local target_tag = target_tag or selected()
+    if target_tag == nil then return end
+    local s_tags = capi.screen[target_tag.screen]:tags()
+
+    -- check the number and state of clients on this tag
+    local clients = target_tag:clients()
+    if #clients > 0 and #s_tags == 1 then
+        return
+    end
+
+    for _, c in pairs(clients) do
+        local c_tags = c:tags()
+        local i_tag = util.table.hasitem(c_tags, target_tag)
+
+        if (not c.sticky) and (#c_tags == 1) then
+            return
+        elseif i_tag ~= nil then
+            table.remove(c_tags, i_tag)
+            if c.sticky then
+                c:tags({fallback_tag} or {s_tags[1]})
+            end
+        end
+    end
+
+    -- delete the tag
+    target_tag.screen = nil
+end
+
 --- Create a set of tags and attach it to a screen.
 -- @param names The tag name, in a table
 -- @param screen The tag screen, or 1 if not set.
-- 
1.7.1


-- 
To unsubscribe, send mail to [email protected].

Reply via email to