awful.tag: Save all "generic" tag properties as real props
Instead of using magic with a weak table, the code now saves this data as a property under the tag object. This avoids all kinds of leaks, for example caused by t.foo = t. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
bf97cb6bfe
commit
ab789e57a9
|
@ -35,7 +35,6 @@ local tag = {object = {}, mt = {} }
|
||||||
-- Private data
|
-- Private data
|
||||||
local data = {}
|
local data = {}
|
||||||
data.history = {}
|
data.history = {}
|
||||||
data.tags = setmetatable({}, { __mode = 'k' })
|
|
||||||
|
|
||||||
-- History functions
|
-- History functions
|
||||||
tag.history = {}
|
tag.history = {}
|
||||||
|
@ -216,7 +215,7 @@ function tag.add(name, props)
|
||||||
local newtag = capi.tag{ name = name }
|
local newtag = capi.tag{ name = name }
|
||||||
|
|
||||||
-- Start with a fresh property table to avoid collisions with unsupported data
|
-- Start with a fresh property table to avoid collisions with unsupported data
|
||||||
data.tags[newtag] = {screen=properties.screen, index=properties.index}
|
newtag.data.awful_tag_properties = {screen=properties.screen, index=properties.index}
|
||||||
|
|
||||||
newtag.activated = true
|
newtag.activated = true
|
||||||
|
|
||||||
|
@ -322,7 +321,7 @@ function tag.object.delete(self, fallback_tag, force)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- delete the tag
|
-- delete the tag
|
||||||
data.tags[self].screen = nil
|
self.data.awful_tag_properties.screen = nil
|
||||||
self.activated = false
|
self.activated = false
|
||||||
|
|
||||||
-- Update all indexes
|
-- Update all indexes
|
||||||
|
@ -1277,7 +1276,7 @@ end
|
||||||
-- @tparam tag _tag The tag.
|
-- @tparam tag _tag The tag.
|
||||||
-- @return The data table.
|
-- @return The data table.
|
||||||
function tag.getdata(_tag)
|
function tag.getdata(_tag)
|
||||||
return data.tags[_tag]
|
return _tag.data.awful_tag_properties
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get a tag property.
|
--- Get a tag property.
|
||||||
|
@ -1289,8 +1288,9 @@ end
|
||||||
-- @tparam string prop The property name.
|
-- @tparam string prop The property name.
|
||||||
-- @return The property.
|
-- @return The property.
|
||||||
function tag.getproperty(_tag, prop)
|
function tag.getproperty(_tag, prop)
|
||||||
if data.tags[_tag] then
|
if not _tag then return end -- FIXME: Turn this into an error?
|
||||||
return data.tags[_tag][prop]
|
if _tag.data.awful_tag_properties then
|
||||||
|
return _tag.data.awful_tag_properties[prop]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1305,12 +1305,12 @@ end
|
||||||
-- @param prop The property name.
|
-- @param prop The property name.
|
||||||
-- @param value The value.
|
-- @param value The value.
|
||||||
function tag.setproperty(_tag, prop, value)
|
function tag.setproperty(_tag, prop, value)
|
||||||
if not data.tags[_tag] then
|
if not _tag.data.awful_tag_properties then
|
||||||
data.tags[_tag] = {}
|
_tag.data.awful_tag_properties = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.tags[_tag][prop] ~= value then
|
if _tag.data.awful_tag_properties[prop] ~= value then
|
||||||
data.tags[_tag][prop] = value
|
_tag.data.awful_tag_properties[prop] = value
|
||||||
_tag:emit_signal("property::" .. prop)
|
_tag:emit_signal("property::" .. prop)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1462,8 +1462,8 @@ capi.screen.connect_signal("removed", function(s)
|
||||||
for _, t in pairs(s.tags) do
|
for _, t in pairs(s.tags) do
|
||||||
t.activated = false
|
t.activated = false
|
||||||
|
|
||||||
if data.tags[t] then
|
if t.data.awful_tag_properties then
|
||||||
data.tags[t].screen = nil
|
t.data.awful_tag_properties.screen = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue