Added option to center the mouse instead of restoring position. Useful
option for users and improves functionality after adding/removing monitors with xrandr.
This commit is contained in:
parent
e7a21947e6
commit
117d086372
|
@ -93,27 +93,34 @@ end
|
||||||
-- @tparam screen _screen Screen number (defaults / falls back to mouse.screen).
|
-- @tparam screen _screen Screen number (defaults / falls back to mouse.screen).
|
||||||
-- @request client activate screen.focus granted The most recent focused client
|
-- @request client activate screen.focus granted The most recent focused client
|
||||||
-- for this screen should be re-activated.
|
-- for this screen should be re-activated.
|
||||||
function screen.focus(_screen)
|
function screen.focus(_screen, ...)
|
||||||
client = client or require("awful.client")
|
client = client or require("awful.client")
|
||||||
if type(_screen) == "number" and _screen > capi.screen.count() then _screen = screen.focused() end
|
if type(_screen) == "number" and _screen > capi.screen.count() then _screen = screen.focused() end
|
||||||
_screen = get_screen(_screen)
|
_screen = get_screen(_screen)
|
||||||
|
if select('#', ...) == 0 then center_mouse = false else center_mouse = select(1, ...) or false end
|
||||||
|
|
||||||
-- screen and pos for current screen
|
-- screen and pos for current screen
|
||||||
local s = get_screen(capi.mouse.screen)
|
local s = get_screen(capi.mouse.screen)
|
||||||
local pos
|
local pos
|
||||||
|
-- center the mouse if requested, else restore previous position
|
||||||
if not _screen.mouse_per_screen then
|
if center_mouse then
|
||||||
-- This is the first time we enter this screen,
|
|
||||||
-- keep relative mouse position on the new screen.
|
|
||||||
pos = capi.mouse.coords()
|
pos = capi.mouse.coords()
|
||||||
local relx = (pos.x - s.geometry.x) / s.geometry.width
|
pos.x = _screen.geometry.x + _screen.geometry.width/2
|
||||||
local rely = (pos.y - s.geometry.y) / s.geometry.height
|
pos.y = _screen.geometry.y + _screen.geometry.height/2
|
||||||
|
|
||||||
pos.x = _screen.geometry.x + relx * _screen.geometry.width
|
|
||||||
pos.y = _screen.geometry.y + rely * _screen.geometry.height
|
|
||||||
else
|
else
|
||||||
-- restore mouse position
|
if not _screen.mouse_per_screen then
|
||||||
pos = _screen.mouse_per_screen
|
-- This is the first time we enter this screen,
|
||||||
|
-- keep relative mouse position on the new screen.
|
||||||
|
pos = capi.mouse.coords()
|
||||||
|
local relx = (pos.x - s.geometry.x) / s.geometry.width
|
||||||
|
local rely = (pos.y - s.geometry.y) / s.geometry.height
|
||||||
|
|
||||||
|
pos.x = _screen.geometry.x + relx * _screen.geometry.width
|
||||||
|
pos.y = _screen.geometry.y + rely * _screen.geometry.height
|
||||||
|
else
|
||||||
|
-- restore mouse position
|
||||||
|
pos = _screen.mouse_per_screen
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- save pointer position of current screen
|
-- save pointer position of current screen
|
||||||
|
|
Loading…
Reference in New Issue