]> git.pld-linux.org Git - packages/awesome-plugin-eminent.git/blame - eminent.lua
- initial
[packages/awesome-plugin-eminent.git] / eminent.lua
CommitLineData
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
20local ipairs = ipairs
21local pairs = pairs
22local awful = require("awful")
23local table = table
24local 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
35module("eminent")
36
37-- Grab the original functions we're replacing
38local deflayout = nil
39local 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
48function 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
61end
62
63-- Pre-create tags
64awful.tag.new = function (names, screen, layout)
65 deflayout = layout and layout[1] or layout
66 return orig.new(names, screen, layout)
67end
68
69-- View tag by relative index
70awful.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
100end
101
102-- Taglist label functions
103awful.widget.taglist.label.all = function (t, args)
104 if t.selected or #t:clients() > 0 then
105 return orig.label(t, args)
106 end
107end
108
109
110-- Update hidden status
111local function uc(c) gettags(c.screen) end
112local function ut(s, t) gettags(s.index) end
113
114capi.client.add_signal("unmanage", uc)
115capi.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)
119end)
120
121for 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)
125end
This page took 0.097544 seconds and 4 git commands to generate.