From ede88d8bcea8328741bdace92a0527b3996a9a21 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 28 Apr 2016 17:42:15 +0200 Subject: [PATCH] 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 --- lib/awful/screen.lua | 2 +- lib/wibox/drawable.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 38af8e97..9c089cad 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -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) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index cf6682e2..9d8627cf 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -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