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 <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Anurag Priyam 2012-01-15 15:58:17 +05:30 committed by Uli Schlachter
parent 9793ec0b71
commit 7f8ef18cd8
1 changed files with 16 additions and 0 deletions

View File

@ -20,6 +20,22 @@ module("awful.screen")
local data = {} local data = {}
data.padding = {} 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. --- Give the focus to a screen, and move pointer.
-- @param screen Screen number. -- @param screen Screen number.
function focus(screen) function focus(screen)