Remember mouse position per screen
The mouse position is saved and restored when focusing another screen If the target screen has no saved mouse position, the relative position of the current screen is used Signed-off-by: lesell_b <lesell_b@epitech.eu>
This commit is contained in:
parent
ee0e9badfa
commit
23b2fae6a9
|
@ -24,6 +24,8 @@ local screen = {}
|
||||||
local data = {}
|
local data = {}
|
||||||
data.padding = {}
|
data.padding = {}
|
||||||
|
|
||||||
|
mouse_per_screen = {}
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Return Xinerama screen number corresponding to the given (pixel) coordinates.
|
-- Return Xinerama screen number corresponding to the given (pixel) coordinates.
|
||||||
-- The number returned can be used as an index into the global
|
-- The number returned can be used as an index into the global
|
||||||
|
@ -44,8 +46,8 @@ function screen.getbycoord(x, y, default)
|
||||||
return default
|
return default
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Give the focus to a screen, and move pointer.
|
--- Give the focus to a screen, and move pointer to last known position on this
|
||||||
-- Keeps relative position of the pointer on the screen.
|
-- screen, or keep position relative to the current focused screen
|
||||||
-- @param _screen Screen number (defaults / falls back to mouse.screen).
|
-- @param _screen Screen number (defaults / falls back to mouse.screen).
|
||||||
function screen.focus(_screen)
|
function screen.focus(_screen)
|
||||||
client = client or require("awful.client")
|
client = client or require("awful.client")
|
||||||
|
@ -53,7 +55,11 @@ function screen.focus(_screen)
|
||||||
|
|
||||||
-- screen and pos for current screen
|
-- screen and pos for current screen
|
||||||
local s = capi.mouse.screen
|
local s = capi.mouse.screen
|
||||||
local pos = capi.mouse.coords()
|
local pos
|
||||||
|
|
||||||
|
if not mouse_per_screen[s] 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
|
-- keep relative mouse position on the new screen
|
||||||
local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width
|
local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width
|
||||||
|
@ -61,6 +67,10 @@ function screen.focus(_screen)
|
||||||
|
|
||||||
pos.x = capi.screen[_screen].geometry.x + relx * capi.screen[_screen].geometry.width
|
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
|
pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height
|
||||||
|
else
|
||||||
|
-- restore mouse position
|
||||||
|
pos = mouse_per_screen[s]
|
||||||
|
end
|
||||||
|
|
||||||
-- move cursor without triggering signals mouse::enter and mouse::leave
|
-- move cursor without triggering signals mouse::enter and mouse::leave
|
||||||
capi.mouse.coords(pos, true)
|
capi.mouse.coords(pos, true)
|
||||||
|
@ -71,7 +81,8 @@ function screen.focus(_screen)
|
||||||
end
|
end
|
||||||
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 to last known position on this
|
||||||
|
-- screen, or keep position relative to the current focused screen
|
||||||
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
||||||
-- @param _screen Screen number.
|
-- @param _screen Screen number.
|
||||||
function screen.focus_bydirection(dir, _screen)
|
function screen.focus_bydirection(dir, _screen)
|
||||||
|
@ -88,8 +99,8 @@ function screen.focus_bydirection(dir, _screen)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Give the focus to a screen, and move pointer, but relative to the current
|
--- Give the focus to a screen, and move pointer to last known position on this
|
||||||
-- focused screen.
|
-- screen, or keep position relative to the current focused screen
|
||||||
-- @param i Value to add to the current focused screen index. 1 will focus next
|
-- @param i Value to add to the current focused screen index. 1 will focus next
|
||||||
-- screen, -1 would focus the previous one.
|
-- screen, -1 would focus the previous one.
|
||||||
function screen.focus_relative(i)
|
function screen.focus_relative(i)
|
||||||
|
|
Loading…
Reference in New Issue