Fix awful.screen.getbycoord when no screens exist

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-05-15 14:43:25 +02:00
parent 13bce88fa0
commit ae738db58a
2 changed files with 15 additions and 2 deletions

View File

@ -86,15 +86,18 @@ end
-- @param x The x coordinate
-- @param y The y coordinate
function screen.getbycoord(x, y)
local dist = math.huge
local s = capi.screen.primary
local dist = screen.object.get_square_distance(s, x, y)
if s then
dist = screen.object.get_square_distance(s, x, y)
end
for i in capi.screen do
local d = screen.object.get_square_distance(i, x, y)
if d < dist then
s, dist = capi.screen[i], d
end
end
return s.index
return s and s.index
end
--- Give the focus to a screen, and move pointer to last known position on this

View File

@ -76,6 +76,16 @@ describe("awful.screen", function()
assert.is.equal(2, ascreen.getbycoord(1, 1))
end)
end)
describe("no screens", function()
before_each(function()
fake_screens = {}
end)
it("getbycoord", function()
assert.is_nil(ascreen.getbycoord(0, 0))
end)
end)
end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80