1 ----------------------------------------------------------------
2 -- Effortless wmii-style dynamic tagging.
3 ----------------------------------------------------------------
4 -- Lucas de Vries <lucas@glacicle.org>
5 -- Licensed under the WTFPL version 2
6 -- * http://sam.zoy.org/wtfpl/COPYING
7 ----------------------------------------------------------------
8 -- To use this module add:
10 -- to the top of your rc.lua.
12 -- That's it. Through magical monkey-patching, all you need to
13 -- do to start dynamic tagging is loading it.
15 -- Use awesome like you normally would, you don't need to
17 ----------------------------------------------------------------
22 local awful = require("awful")
31 keygrabber = keygrabber,
34 -- Eminent: Effortless wmii-style dynamic tagging
37 -- Grab the original functions we're replacing
41 viewidx = awful.tag.viewidx,
43 taglist = awful.widget.taglist.new,
44 label = awful.widget.taglist.label.all,
47 -- Return tags with stuff on them, mark others hidden
48 function gettags(screen)
51 for k, t in ipairs(capi.screen[screen]:tags()) do
52 if t.selected or #t:clients() > 0 then
53 awful.tag.setproperty(t, "hide", false)
56 awful.tag.setproperty(t, "hide", true)
64 awful.tag.new = function (names, screen, layout)
65 deflayout = layout and layout[1] or layout
66 return orig.new(names, screen, layout)
69 -- View tag by relative index
70 awful.tag.viewidx = function (i, screen)
72 local s = screen and screen.index or capi.mouse.screen
73 local ctags = capi.screen[s]:tags()
74 local tags = gettags(s)
75 local sel = awful.tag.selected()
77 -- Check if we should "create" a new tag
78 local selidx = awful.util.table.hasitem(tags, sel)
79 local tagidx = awful.util.table.hasitem(ctags, sel)
81 -- Create a new tag if needed
82 if selidx == #tags and i == 1 and #sel:clients() > 0 then
86 if #ctags >= tagidx+1 then
88 ctags[tagidx+1].selected = true
91 local tag = capi.tag { name = ""..(tagidx+1) }
94 awful.tag.setproperty(tag, "layout", deflayout)
98 orig.viewidx(i, screen)
102 -- Taglist label functions
103 awful.widget.taglist.label.all = function (t, args)
104 if t.selected or #t:clients() > 0 then
105 return orig.label(t, args)
110 -- Update hidden status
111 local function uc(c) gettags(c.screen) end
112 local function ut(s, t) gettags(s.index) end
114 capi.client.add_signal("unmanage", uc)
115 capi.client.add_signal("new", function(c)
116 c:add_signal("property::screen", uc)
117 c:add_signal("tagged", uc)
118 c:add_signal("untagged", uc)
121 for screen=1, capi.screen.count() do
122 awful.tag.attached_add_signal(screen, "property::selected", uc)
123 capi.screen[screen]:add_signal("tag::attach", ut)
124 capi.screen[screen]:add_signal("tag::detach", ut)