From b1b9bd838d57746abbedf197f2bfdf4892bbd81a Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 14 Sep 2020 00:19:57 -0700 Subject: [PATCH] tag: Add a `:clear()` method. It was previously done using `:clients{}`, but that super unintuitive, hard to search and has no signal. This fixed that. --- lib/awful/tag.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua index 17b162e8..61526e80 100644 --- a/lib/awful/tag.lua +++ b/lib/awful/tag.lua @@ -349,6 +349,42 @@ function tag.find_fallback(screen, invalids) end end +--- When all clients are removed from the tag. +-- @signal cleared +-- @see clear + +--- Remove all tagged clients. +-- @method clear +-- @tparam table args The arguments. +-- @tparam tag args.fallback_tag A fallback tag. +-- @tparam[opt=false] boolean args.allow_untagged Allow the untagged clients to remain untagged. +-- @emits cleared After all clients have been untagged. +-- @emits untagged For each currently tagged clients. +-- @emitstparam untagged client c The untagged client. +function tag.object.clear(self, args) + args = args or {} + + local clients = self:clients() + + -- Clear + self:clients({}) + + if #clients > 0 and not args.allow_untagged then + local target_scr = get_screen(tag.getproperty(self, "screen")) + local fallback_tag = args.fallback_tag or tag.find_fallback(target_scr, {self}) + + if not fallback_tag then return end + + for _, c in ipairs(clients) do + if #c:tags() == 0 then + c:tags({fallback_tag}) + end + end + end + + self:emit_signal("cleared") +end + --- Delete a tag. -- -- To delete the current tag: