Merge pull request #1051 from Elv13/fix_tag_index

tag: Fix index calculation.
This commit is contained in:
Emmanuel Lepage Vallée 2016-08-22 18:09:03 -04:00 committed by GitHub
commit 68aae5ff62
4 changed files with 34 additions and 7 deletions

View File

@ -83,7 +83,7 @@ install:
- travis_retry sudo luarocks install luacheck - travis_retry sudo luarocks install luacheck
# Install ldoc for building docs. # 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 - travis_retry sudo luarocks install lua-discount
# Install dependencies for code coverage testing. # Install dependencies for code coverage testing.

View File

@ -412,7 +412,7 @@ function screen.object.get_tags(s, unordered)
-- Avoid infinite loop, + save some time -- Avoid infinite loop, + save some time
if not unordered then if not unordered then
table.sort(tags, function(a, b) 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)
end end

View File

@ -74,6 +74,12 @@ function tag.object.set_index(self, idx)
-- screen.tags cannot be used as it depend on index -- screen.tags cannot be used as it depend on index
local tmp_tags = raw_tags(scr) 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 if (not idx) or (idx < 1) or (idx > #tmp_tags) then
return return
end end
@ -97,13 +103,14 @@ function tag.object.set_index(self, idx)
end end
function tag.object.get_index(query_tag) 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") local idx = tag.getproperty(query_tag, "index")
if idx then return idx end if idx then return idx end
-- Get an unordered list of tags
local tags = raw_tags(query_tag.screen)
-- Too bad, lets compute it -- Too bad, lets compute it
for i, t in ipairs(tags) do for i, t in ipairs(tags) do
if t == query_tag then if t == query_tag then

View File

@ -3,6 +3,14 @@ local beautiful = require("beautiful")
awful.util.deprecate = function() end 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 has_spawned = false
local steps = { local steps = {
@ -20,29 +28,39 @@ local tags = mouse.screen.tags
assert(#mouse.screen.tags == 9) assert(#mouse.screen.tags == 9)
for k, v in ipairs(tags) do check_order()
assert(k == v.index)
end
tags[7].index = 9 tags[7].index = 9
assert(tags[7].index == 9) assert(tags[7].index == 9)
check_order()
tags[7].index = 4 tags[7].index = 4
assert(tags[7].index == 4) assert(tags[7].index == 4)
check_order()
awful.tag.move(5, tags[7]) awful.tag.move(5, tags[7])
assert(tags[7].index == 5) assert(tags[7].index == 5)
check_order()
tags[1]:swap(tags[3]) tags[1]:swap(tags[3])
check_order()
assert(tags[1].index == 3) assert(tags[1].index == 3)
assert(tags[3].index == 1) assert(tags[3].index == 1)
check_order()
awful.tag.swap(tags[1], tags[3]) awful.tag.swap(tags[1], tags[3])
assert(tags[3].index == 3) assert(tags[3].index == 3)
assert(tags[1].index == 1) assert(tags[1].index == 1)
check_order()
-- Test add, icon and delete -- Test add, icon and delete
client.focus = client.get()[1] 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}) local t = awful.tag.add("Test", {clients={c}, icon = beautiful.awesome_icon})
check_order()
local found = false local found = false
tags = mouse.screen.tags tags = mouse.screen.tags