]>
Commit | Line | Data |
---|---|---|
48f2fdd9 ZU |
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: | |
9 | -- require("eminent") | |
10 | -- to the top of your rc.lua. | |
11 | -- | |
12 | -- That's it. Through magical monkey-patching, all you need to | |
13 | -- do to start dynamic tagging is loading it. | |
14 | -- | |
15 | -- Use awesome like you normally would, you don't need to | |
16 | -- change a thing. | |
17 | ---------------------------------------------------------------- | |
18 | ||
19 | -- Grab environment | |
20 | local ipairs = ipairs | |
21 | local pairs = pairs | |
22 | local awful = require("awful") | |
23 | local table = table | |
24 | local capi = { | |
25 | tag = tag, | |
26 | mouse = mouse, | |
27 | client = client, | |
28 | screen = screen, | |
29 | wibox = wibox, | |
30 | timer = timer, | |
31 | keygrabber = keygrabber, | |
32 | } | |
33 | ||
34 | -- Eminent: Effortless wmii-style dynamic tagging | |
35 | module("eminent") | |
36 | ||
37 | -- Grab the original functions we're replacing | |
38 | local deflayout = nil | |
39 | local orig = { | |
40 | new = awful.tag.new, | |
41 | viewidx = awful.tag.viewidx, | |
42 | ||
43 | taglist = awful.widget.taglist.new, | |
44 | label = awful.widget.taglist.label.all, | |
45 | } | |
46 | ||
47 | -- Return tags with stuff on them, mark others hidden | |
48 | function gettags(screen) | |
49 | local tags = {} | |
50 | ||
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) | |
54 | table.insert(tags, t) | |
55 | else | |
56 | awful.tag.setproperty(t, "hide", true) | |
57 | end | |
58 | end | |
59 | ||
60 | return tags | |
61 | end | |
62 | ||
63 | -- Pre-create tags | |
64 | awful.tag.new = function (names, screen, layout) | |
65 | deflayout = layout and layout[1] or layout | |
66 | return orig.new(names, screen, layout) | |
67 | end | |
68 | ||
69 | -- View tag by relative index | |
70 | awful.tag.viewidx = function (i, screen) | |
71 | -- Hide tags | |
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() | |
76 | ||
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) | |
80 | ||
81 | -- Create a new tag if needed | |
82 | if selidx == #tags and i == 1 and #sel:clients() > 0 then | |
83 | -- Deselect all | |
84 | awful.tag.viewnone(s) | |
85 | ||
86 | if #ctags >= tagidx+1 then | |
87 | -- Focus next | |
88 | ctags[tagidx+1].selected = true | |
89 | else | |
90 | -- Create new | |
91 | local tag = capi.tag { name = ""..(tagidx+1) } | |
92 | tag.screen = s | |
93 | tag.selected = true | |
94 | awful.tag.setproperty(tag, "layout", deflayout) | |
95 | end | |
96 | else | |
97 | -- Call original | |
98 | orig.viewidx(i, screen) | |
99 | end | |
100 | end | |
101 | ||
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) | |
106 | end | |
107 | end | |
108 | ||
109 | ||
110 | -- Update hidden status | |
111 | local function uc(c) gettags(c.screen) end | |
112 | local function ut(s, t) gettags(s.index) end | |
113 | ||
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) | |
119 | end) | |
120 | ||
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) | |
125 | end |