summaryrefslogtreecommitdiff
path: root/func/tagnames.lua
blob: 0274b7eb5526b7e363640789fed1c30666a747ce (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
local nametag_format = "%s: %s"

function nametag(t, name)
	-- set tag basename
	if t.basename == nil then
		t.basename = t.name
	end

	if name == nil then
		t.name = t.basename
		return
	end

	t.name = string.format(nametag_format, t.basename, name)
end

function nametagc_t(t, c)
	local cs = t.screen:get_all_clients(true)
	if c then
		table.insert(cs, c)
	end

	for _, c in ipairs(cs) do
		for _, ct in ipairs(c:tags()) do
			if ct == t then
				nametag(t, c.newclass or c.class)
				return
			end
		end
	end
	nametag(t)
end

-- without client
function nametagc_t_u(t)
	nametagc_t(t)
end

function nametagc_c(c)
	for _, ct in ipairs(c:tags()) do
		nametagc_t(ct, c)
	end
end

tag.connect_signal("tagged",    nametagc_t)
tag.connect_signal("untagged",  nametagc_t_u)
client.connect_signal("raised", nametagc_c)
client.connect_signal("property::class", nametagc_c)