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. 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 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 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