From bbfa6006f3488edd7e78ed4f896c66c49fa1717f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 22 Aug 2016 00:40:21 -0400 Subject: [PATCH 1/4] 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 From 99657f49cfaeb2f9bc381c5416f06fa1eb053043 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 22 Aug 2016 23:03:10 +0200 Subject: [PATCH 2/4] Travis: pin ldoc at 1.4.4 Ref: https://github.com/awesomeWM/awesome/pull/1051#issuecomment-241327733 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 258add8b..740dffcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -83,7 +83,7 @@ install: - travis_retry sudo luarocks install luacheck # Install ldoc for building docs. - - travis_retry sudo luarocks install ldoc + - travis_retry sudo luarocks install ldoc 1.4.4 - travis_retry sudo luarocks install lua-discount # Install dependencies for code coverage testing. From f2bb0ab87101ea752f8f72b9d2497f3d747111bb Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 22 Aug 2016 17:25:50 -0400 Subject: [PATCH 3/4] tests: Test the tag index more often --- tests/test-awful-tag.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/test-awful-tag.lua b/tests/test-awful-tag.lua index 076cd0b3..3f684ad6 100644 --- a/tests/test-awful-tag.lua +++ b/tests/test-awful-tag.lua @@ -3,6 +3,14 @@ local beautiful = require("beautiful") awful.util.deprecate = function() end +local function check_order() + local tags = mouse.screen.tags + + for k, v in ipairs(tags) do + assert(k == v.index) + end +end + local has_spawned = false local steps = { @@ -20,29 +28,39 @@ local tags = mouse.screen.tags assert(#mouse.screen.tags == 9) -for k, v in ipairs(tags) do - assert(k == v.index) -end +check_order() tags[7].index = 9 assert(tags[7].index == 9) +check_order() + tags[7].index = 4 assert(tags[7].index == 4) +check_order() + awful.tag.move(5, tags[7]) assert(tags[7].index == 5) +check_order() + tags[1]:swap(tags[3]) +check_order() + assert(tags[1].index == 3) assert(tags[3].index == 1) +check_order() + awful.tag.swap(tags[1], tags[3]) assert(tags[3].index == 3) assert(tags[1].index == 1) +check_order() + -- Test add, icon and delete client.focus = client.get()[1] @@ -52,6 +70,8 @@ assert(beautiful.awesome_icon) local t = awful.tag.add("Test", {clients={c}, icon = beautiful.awesome_icon}) +check_order() + local found = false tags = mouse.screen.tags From 01db39f5bbe106fddcb117e6fcb03e91ba057ac3 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 22 Aug 2016 17:27:31 -0400 Subject: [PATCH 4/4] screen: Use math.huge instead of 9999 --- lib/awful/screen.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index b75e4666..4029895b 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -412,7 +412,7 @@ function screen.object.get_tags(s, unordered) -- Avoid infinite loop, + save some time if not unordered then table.sort(tags, function(a, b) - return (a.index or 9999) < (b.index or 9999) + return (a.index or math.huge) < (b.index or math.huge) end) end