summaryrefslogtreecommitdiff
path: root/func/tagnames.lua
blob: fcd01a42fa4398595b344cc35febb524bea84322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--TODO find out why it doesnt work at start
--local awful = require("awful")

function nametags(s)
	local tags = s.tags
	for _, tag in ipairs(tags) do
		-- set tag basename
		if tag.basename == nil then
			tag.basename = tag.name
		end

		-- check if tag has any clients. if not, use basename
		if next(tag:clients()) == nil then
			tag.name = tag.basename
		else
			-- loop over all screen clients (ordered top to bottom)
			local hastag = nil
			for _, c in ipairs(s.clients) do
				-- test if client in on the tag
				for _, ctag in ipairs(c:tags()) do
					if ctag == tag then
						hastag = c
						break
					end
				end
				-- if it does, this will be the tag name. so break
				if hastag ~= nil then
					break
				end
			end
			-- set tag name
			-- there should always be a tag since we checked above so if there isnt then there is clearly a problem
			--TODO remove this if statement
			if hastag then
				tag.name = tag.basename .. ": " .. hastag.class
			end
		end
	end
end

function nametagsc(c)
	nametags(c.screen)
end

client.connect_signal("manage",   nametagsc)
client.connect_signal("swapped",  nametagsc)
client.connect_signal("tagged",   nametagsc)
client.connect_signal("unmanage", nametagsc)
client.connect_signal("untagged", nametagsc)

--awful.screen.connect_for_each_screen(nametags)