awful.tag.delete(tag)
    deletes tags if there are zero or only sticky clients on them
---
 lib/awful/tag.lua.in |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in
index dfa78f8..c8b54ce 100644
--- a/lib/awful/tag.lua.in
+++ b/lib/awful/tag.lua.in
@@ -76,6 +76,31 @@ function new(names, screen, layout)
     return tags
 end
 
+--- Delete a tag
+-- @param target_tag Optional tag object to delete, [tag.selected()]
+function delete(target_tag)
+    -- abort if no tag is passed or currently selected
+    local target_tag = target_tag or selected()
+    if target_tag == nil then return end
+
+    -- check the number and state of clients on this tag
+    -- sticky clients don't count against deletion
+    local clients = target_tag:clients()
+    local num_clients = #clients
+    for _, c in pairs(clients) do
+        if c.sticky then
+            num_clients = num_clients - 1
+        end
+    end
+
+    if num_clients > 0 then return end
+
+    -- delete the tag
+    target_tag.screen = nil
+
+    history.restore(scr, 1)
+end
+
 --- Rename a tag
 -- @param target_tag The tag to rename, [selected()]
 -- @param name Optional new name, a string [selected().name]
-- 
1.7.0.1


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

Reply via email to