From 7f8ef18cd83531523678849d0004f2aa2652b19a Mon Sep 17 00:00:00 2001 From: Anurag Priyam Date: Sun, 15 Jan 2012 15:58:17 +0530 Subject: [PATCH] awful.screen: define getbycoord() to compute screen number of a pixel Given an object's coordinates, `awful.screen.getbycoord` can be used to determine the screen than the object is, or should be attached to. Signed-off-by: Anurag Priyam Signed-off-by: Uli Schlachter --- lib/awful/screen.lua.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/awful/screen.lua.in b/lib/awful/screen.lua.in index d15d5166..9fba87b8 100644 --- a/lib/awful/screen.lua.in +++ b/lib/awful/screen.lua.in @@ -20,6 +20,22 @@ module("awful.screen") local data = {} data.padding = {} +--- +-- Return Xinerama screen number corresponding to the given (pixel) coordinates. +-- The number returned can be used as an index into the global +-- `screen` table/object. +-- @param x The x coordinate +-- @param y The y coordinate +function getbycoord(x, y) + for i = 1, capi.screen:count() do + local geometry = capi.screen[i].geometry + if((x < 0 or (x >= geometry.x and x < geometry.x + geometry.width)) + and (y < 0 or (y >= geometry.y and y < geometry.y + geometry.height))) then + return i; + end + end +end + --- Give the focus to a screen, and move pointer. -- @param screen Screen number. function focus(screen)