On 7/12/10, Julien Danjou <[email protected]> wrote: > On Sat, Jul 10 2010, Aneesh Kumar wrote: > >> I looked at merging the earlier set of patches i found on the mailing >> list with upstream -git. The only missing features for a working >> dyntag feature is delete and rename (we can skip move_screen i guess). >> >> Is it possible to get tag.delete() merged upstream ? >> >> Last mail on this is here >> >> http://www.mail-archive.com/[email protected]/msg05142.html >> >> but that is missing find_fallback function. So i ended up using >> >> http://www.mail-archive.com/[email protected]/msg05112.html >> >> With delete upstream i should be able to use the upstream source directly. > > It seems we lost track of this set of patches. > > Perry, would you be kind enough and resent a whole set of patches that > me or Uli can review and merge? > > My apologies. >
With the attached patch we should be able to have a minimal dynamic tagging feature set. This is the last patch in the mail thread i mentioned in previous mail. I just added find_fallback function to this patch -aneesh
commit 5451dd110c81d2a29697c9e60233c64351c27cfe Author: Perry Hargrave <[email protected]> Date: Sat Jul 10 13:14:28 2010 +0530 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] diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in index af1b043..7c02802 100644 --- a/lib/awful/tag.lua.in +++ b/lib/awful/tag.lua.in @@ -75,6 +75,74 @@ function add(name, props) return newtag end +--- Find a suitable fallback tag. +-- @param screen The screen number to look for a tag on. [mouse.screen] +-- @param target A table of tags we consider unacceptable. [{selected()}] +function find_fallback(screen, invalids) + local scr = screen or capi.mouse.screen + local t = invalids or {selected()} + + for _, v in pairs(capi.screen[scr]:tags()) do + if not util.table.hasitem(t, v) then return v end + 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.
