From ae738db58a230ea5c7e3a94467b11671dad38427 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 15 May 2016 14:43:25 +0200 Subject: [PATCH] Fix awful.screen.getbycoord when no screens exist Signed-off-by: Uli Schlachter --- lib/awful/screen.lua | 7 +++++-- spec/awful/screen_spec.lua | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 48d531eee..b2f2543e8 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -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 diff --git a/spec/awful/screen_spec.lua b/spec/awful/screen_spec.lua index 0967b1768..6c36daad6 100644 --- a/spec/awful/screen_spec.lua +++ b/spec/awful/screen_spec.lua @@ -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