Update saved mouse position on screen focus change

Signed-off-by: lesell_b <lesell_b@epitech.eu>
This commit is contained in:
lesell_b 2015-10-08 04:40:59 +02:00
parent 23b2fae6a9
commit f2b6aa105c
1 changed files with 5 additions and 4 deletions

View File

@ -57,10 +57,8 @@ function screen.focus(_screen)
local s = capi.mouse.screen
local pos
if not mouse_per_screen[s] then
if not mouse_per_screen[_screen] then
-- This is the first time we enter this screen,
mouse_per_screen[s] = capi.mouse.coords()
-- keep relative mouse position on the new screen
local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width
local rely = (pos.y - capi.screen[s].geometry.y) / capi.screen[s].geometry.height
@ -69,9 +67,12 @@ function screen.focus(_screen)
pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height
else
-- restore mouse position
pos = mouse_per_screen[s]
pos = mouse_per_screen[_screen]
end
-- save pointer position of current screen
mouse_per_screen[s] = capi.mouse.coords()
-- move cursor without triggering signals mouse::enter and mouse::leave
capi.mouse.coords(pos, true)