awful.screen: Save last mouse position as screen property

Instead of using a weak table to save the last mouse position, this is
now saved directly as a property under the screen.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-10-05 21:00:47 +02:00
parent 3d048dca04
commit 4ef63d9416
1 changed files with 3 additions and 5 deletions

View File

@ -31,8 +31,6 @@ local screen = {object={}}
local data = {}
data.padding = {}
screen.mouse_per_screen = setmetatable({}, {__mode="k"})
--- Take an input geometry and substract/add a delta.
-- @tparam table geo A geometry (width, height, x, y) table.
-- @tparam table delta A delta table (top, bottom, x, y).
@ -99,7 +97,7 @@ function screen.focus(_screen)
local s = get_screen(capi.mouse.screen)
local pos
if not screen.mouse_per_screen[_screen] then
if not _screen.mouse_per_screen then
-- This is the first time we enter this screen,
-- keep relative mouse position on the new screen.
pos = capi.mouse.coords()
@ -110,11 +108,11 @@ function screen.focus(_screen)
pos.y = _screen.geometry.y + rely * _screen.geometry.height
else
-- restore mouse position
pos = screen.mouse_per_screen[_screen]
pos = _screen.mouse_per_screen
end
-- save pointer position of current screen
screen.mouse_per_screen[s] = capi.mouse.coords()
s.mouse_per_screen = capi.mouse.coords()
-- move cursor without triggering signals mouse::enter and mouse::leave
capi.mouse.coords(pos, true)