Fix awful.screen.getbycoord when no screens exist

When there are no screens, screen[1] causes an error. Thus, this isn't a safe
fallback for these functions. Instead, this commit makes the code prefer the
primary screen, if possible. If no screen exists, then screen.primary will be
nil, but at least it won't throw an error like screen[1] does.

(This also changes the outdated copy of getbycoord that exists in
wibox.drawable)

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-04-28 17:42:15 +02:00
parent 201090100b
commit ede88d8bce
2 changed files with 2 additions and 2 deletions

View File

@ -86,7 +86,7 @@ end
-- @param x The x coordinate
-- @param y The y coordinate
function screen.getbycoord(x, y)
local s = capi.screen[1]
local s = capi.screen.primary
local dist = screen.object.get_square_distance(s, x, y)
for i in capi.screen do
local d = screen.object.get_square_distance(i, x, y)

View File

@ -35,7 +35,7 @@ local function screen_getbycoord(x, y)
return capi.screen[i]
end
end
return capi.screen[1]
return capi.screen.primary
end
-- Get the widget context. This should always return the same table (if