-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Am 29.05.2010 01:39, Perry Hargrave wrote:
> 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()

It might be necessary to check that target_tag and fallback_tag are different.
Also, if target_tag is the first tag on that screen and no fallback_tag is
given, the code below might leave sticky clients attached to no tag.
My proposal (see below for the first line):

  -- Find a suitable fallback tag for moving clients to
  local fallback_tag = fallback_tag
  if fallback_tag == target_tag then return end

  -- If no fallback tag is given, use the first suitable one
  if fallback_tag == nil then
     if target_tag ~= s_tags[1] then
         fallback_tag = s_tags[1]
     else
         fallback_tag = s_tags[2]
     end
  end

It looks a lot more complicated, but I think it handles all corner cases.

> +
> +    -- 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

I'd add a comment here:

  -- Move affected clients to the fallback_tag
(or something like that)

> +    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)

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...

> +            if c.sticky then
> +                c:tags({fallback_tag} or {s_tags[1]})

This won't work, you'll always get  {fallback_tag} which just might be an empty
table. You need { fallback_tag or s_tags[1] }. It might be easier to move that
check to the beginning of the function:

  local fallback_tag = 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.


- -- 
- - Buck, when, exactly, did you lose your mind?
- - Three months ago. I woke up one morning married to a pineapple.
  An ugly pineapple... But I loved her!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBCAAGBQJMALTKAAoJECLkKOvLj8sGk1wIAITaU39ypMVx1XJraFTDs7ey
2gJzL1Gpd75Ymk0vaOqbNvIF8ikcL1trK4hGkPnw/l7QoLtAxIA/kQQAfBxJ2vbD
k00ZjZ/n29U6hMVpp75A80ezp5ShMOq+A5kQvstpHATOz4Jl7GYiL0BpSYiTFJ+M
ORoCXP/nBzgno5wDFZQz5xokuZl9mul+/Emw5X1aK2F3PVsNBOXAvrncUYm41NWR
4/jIvMO43QhTo0irX2NrtSL4XynzeMCcZOJ2/LPX5J1N7L3Lvt23fgiWv3aQXk5w
vU+z8cwiLthuIEFuAl0FdN5zjrM88LJlqrdd3mbveQhiQxSFLmRyMPteHTFc9IE=
=TOuG
-----END PGP SIGNATURE-----

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

Reply via email to