gears.geometry: Mutualize getbycoord
This commit is contained in:
parent
251614afff
commit
dd121623b5
|
@ -57,4 +57,23 @@ function gears.geometry.rectangle.get_closest_by_coord(list, x, y)
|
|||
return ret
|
||||
end
|
||||
|
||||
--- Return the rectangle containing the [x, y] point.
|
||||
--
|
||||
-- Note that if multiple element from the geometry list contains the point, the
|
||||
-- returned result is nondeterministic.
|
||||
--
|
||||
-- @tparam table list A list of geometry tables.
|
||||
-- @tparam number x The x coordinate
|
||||
-- @tparam number y The y coordinate
|
||||
-- @return The key from the closest geometry. In case no result is found, *nil*
|
||||
-- is returned.
|
||||
function gears.geometry.rectangle.get_by_coord(list, x, y)
|
||||
for k, geometry in pairs(list) do
|
||||
if x >= geometry.x and x < geometry.x + geometry.width
|
||||
and y >= geometry.y and y < geometry.y + geometry.height then
|
||||
return k
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return gears.geometry
|
||||
|
|
|
@ -19,30 +19,26 @@ local color = require("gears.color")
|
|||
local object = require("gears.object")
|
||||
local surface = require("gears.surface")
|
||||
local timer = require("gears.timer")
|
||||
local grect = require("gears.geometry").rectangle
|
||||
local matrix = require("gears.matrix")
|
||||
local hierarchy = require("wibox.hierarchy")
|
||||
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||
|
||||
local drawables = setmetatable({}, { __mode = 'k' })
|
||||
|
||||
-- This is awful.screen.getbycoord() which we sadly cannot use from here (cyclic
|
||||
-- dependencies are bad!)
|
||||
local function screen_getbycoord(x, y)
|
||||
for i in screen do
|
||||
local geometry = screen[i].geometry
|
||||
if x >= geometry.x and x < geometry.x + geometry.width
|
||||
and y >= geometry.y and y < geometry.y + geometry.height then
|
||||
return capi.screen[i]
|
||||
end
|
||||
end
|
||||
return capi.screen.primary
|
||||
end
|
||||
|
||||
-- Get the widget context. This should always return the same table (if
|
||||
-- possible), so that our draw and fit caches can work efficiently.
|
||||
local function get_widget_context(self)
|
||||
local geom = self.drawable:geometry()
|
||||
local s = screen_getbycoord(geom.x, geom.y)
|
||||
|
||||
local sgeos = {}
|
||||
|
||||
for s in capi.screen do
|
||||
sgeos[s] = s.geometry
|
||||
end
|
||||
|
||||
local s = grect.get_by_coord(sgeos, geom.x, geom.y) or capi.screen.primary
|
||||
|
||||
local context = self._widget_context
|
||||
local dpi = beautiful.xresources.get_dpi(s)
|
||||
if (not context) or context.screen ~= s or context.dpi ~= dpi then
|
||||
|
|
Loading…
Reference in New Issue