Makes awful.screen.focus keep the cursor position on screen

When changing focus to an other screen, awful.screen.focus keeps relative
position of the cursor, instead of moving to the top left corner. Does not
trigger mouse:enter and mouse:leave signals.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Abdó Roig-Maranges 2012-09-14 20:14:22 +02:00 committed by Uli Schlachter
parent 0e2960ebf3
commit 34c1c7d416
1 changed files with 17 additions and 3 deletions

View File

@ -37,14 +37,28 @@ function screen.getbycoord(x, y)
end end
end end
--- Give the focus to a screen, and move pointer. --- Give the focus to a screen, and move pointer. Keeps relative position of the pointer on the screen.
-- @param screen Screen number. -- @param screen Screen number.
function screen.focus(_screen) function screen.focus(_screen)
if _screen > capi.screen.count() then _screen = capi.mouse.screen end if _screen > capi.screen.count() then _screen = capi.mouse.screen end
-- screen and pos for current screen
local s = capi.mouse.screen
local pos = 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
pos.x = capi.screen[_screen].geometry.x + relx * capi.screen[_screen].geometry.width
pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height
-- move cursor without triggering signals mouse::enter and mouse::leave
capi.mouse.screen = _screen
capi.mouse.coords(pos, true)
local c = client.focus.history.get(_screen, 0) local c = client.focus.history.get(_screen, 0)
if c then capi.client.focus = c end if c then capi.client.focus = c end
-- Move the mouse on the screen
capi.mouse.screen = _screen
end end
--- Give the focus to a screen, and move pointer, by physical position relative to current screen. --- Give the focus to a screen, and move pointer, by physical position relative to current screen.