Fix awful.screen.getbycoord when no screens exist
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
13bce88fa0
commit
ae738db58a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue