On Sat, May 29, 2010 at 08:46:31AM +0200, Uli Schlachter wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Am 29.05.2010 08:31, Uli Schlachter wrote:
> > It's nice to clean up properly, but AFAIK target_tag.screen = nil already
> > removes all clients from the affected tag. I'm not sure if it's clearer to
> > do it
> > explicitly or not...
>
> Seems like I'm wrong on that one....?
>
I think you were correct. I tested with something like this:
clients = awful.tag.selected():clients()
tag.delete()
for _,c in pairs(clients) do
for _, t in pairs(c:tags()) do
print(c.name, t.name)
end
end
and the deleted tag was not shown. It would feel better to verify
this other than empirically, but I didn't find it.
So here attached is something using the 'find_fallback' function. I also
added a 'feature' to try and prevent staring at selected() == nil.
Someone was opposed to doing history.restore() in my previous set but
this time I only call it if no tag is currently visible. Which I think
is just 'doing the right thing'
--
perry
>From 7bc97b5fbe9a822e75685012d92aa93b1b7ca6fd Mon Sep 17 00:00:00 2001
From: Perry Hargrave <[email protected]>
Date: Fri, 28 May 2010 10:52:55 -0700
Subject: [PATCH] tag.lua: delete() intelligently delete tags
tag.delete(t, fb):
Delete tags if certain criteria are met:
- There are no clients assigned exclusively to this tag.
- Stickied clients have somewhere to go, 'fb' the fallback tag
If after deleting there is no tag selected then try and
history.restore() or select the first tag on the screen.
Return true if successful and nil otherwise.
Signed-off-by: Perry Hargrave <[email protected]>
---
lib/awful/tag.lua.in | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in
index d3f0bac..39d2213 100644
--- a/lib/awful/tag.lua.in
+++ b/lib/awful/tag.lua.in
@@ -58,6 +58,62 @@ function find_fallback(screen, invalids)
end
end
+--- Delete a tag.
+-- @param target_tag Optional tag object to delete. [selected()]
+-- @param fallback_tag Tag to assign stickied tags to. [~selected()]
+-- @return Returns true if the tag is successfully deleted, nil otherwise.
+-- If there are no clients exclusively on this tag then delete it. Any
+-- stickied clients are assigned to the optional 'fallback_tag'.
+-- If after deleting the tag there is no selected tag, try and restore from
+-- history or select the first tag on the screen.
+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 ntags = #capi.screen[target_tag.screen]:tags()
+ local target_scr = target_tag.screen
+
+ -- We can't use the target tag as a fallback.
+ local fallback_tag = fallback_tag
+ if fallback_tag == target_tag then return end
+
+ -- No fallback_tag provided, try and get one.
+ if fallback_tag == nil then
+ fallback_tag = find_fallback(target_scr, {target_tag})
+ end
+
+ -- Abort if we would have un-tagged clients.
+ local clients = target_tag:clients()
+ if #clients > 0 and ntags == 1 then return end
+
+ -- Move the clients we can off of this tag.
+ for _, c in pairs(clients) do
+
+ -- If a client has only this tag, or stickied clients with
+ -- nowhere to go, abort.
+ if (not c.sticky) and (#c:tags() == 1) or
+ (c.sticky and fallback_tag == nil) then
+ return
+ else
+ c:tags({fallback_tag})
+ end
+ end
+
+ -- delete the tag
+ target_tag.screen = nil
+
+ -- If no tags are visible, try and view one.
+ if selected(target_scr) == nil and ntags > 0 then
+ history.restore()
+ if selected(target_scr) == nil then
+ capi.screen[target_scr]:tags()[1].selected = true
+ end
+ end
+
+ return true
+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