From bbfa6006f3488edd7e78ed4f896c66c49fa1717f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 22 Aug 2016 00:40:21 -0400 Subject: [PATCH] tag: Fix index calculation. The index was updated on an unordered table. As the elements order did not match the relative indices once they have been changed, further calls to set_index produced garbage. The default taglist didn't notice because it use screen.tags table index instead of the tag index. A debug using echo 'for _,t in ipairs(mouse.screen.tags) do print("INDEX:", _, t.index, t.name) end' | awesome-client Would have shown two or more elements with the same index. To debug issues related to tag indices, this bash script can be enabled: while true; do echo 'for _,t in ipairs(mouse.screen.tags) do assert( _==t.index) end' | awesome-client sleep 0.5 done --- lib/awful/tag.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua index fc1b1e60..7be30a82 100644 --- a/lib/awful/tag.lua +++ b/lib/awful/tag.lua @@ -74,6 +74,12 @@ function tag.object.set_index(self, idx) -- screen.tags cannot be used as it depend on index local tmp_tags = raw_tags(scr) + -- sort the tags by index + table.sort(tmp_tags, function(a, b) + local ia, ib = tag.getproperty(a, "index"), tag.getproperty(b, "index") + return (ia or math.huge) < (ib or math.huge) + end) + if (not idx) or (idx < 1) or (idx > #tmp_tags) then return end @@ -97,13 +103,14 @@ function tag.object.set_index(self, idx) end function tag.object.get_index(query_tag) - -- Get an unordered list of tags - local tags = raw_tags(query_tag.screen) local idx = tag.getproperty(query_tag, "index") if idx then return idx end + -- Get an unordered list of tags + local tags = raw_tags(query_tag.screen) + -- Too bad, lets compute it for i, t in ipairs(tags) do if t == query_tag then