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,15 +93,21 @@ end
|
|||
-- @tparam screen _screen Screen number (defaults / falls back to mouse.screen).
|
||||
-- @request client activate screen.focus granted The most recent focused client
|
||||
-- for this screen should be re-activated.
|
||||
function screen.focus(_screen)
|
||||
function screen.focus(_screen, ...)
|
||||
client = client or require("awful.client")
|
||||
if type(_screen) == "number" and _screen > capi.screen.count() then _screen = screen.focused() end
|
||||
_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
|
||||
local s = get_screen(capi.mouse.screen)
|
||||
local pos
|
||||
|
||||
-- center the mouse if requested, else restore previous position
|
||||
if center_mouse then
|
||||
pos = capi.mouse.coords()
|
||||
pos.x = _screen.geometry.x + _screen.geometry.width/2
|
||||
pos.y = _screen.geometry.y + _screen.geometry.height/2
|
||||
else
|
||||
if not _screen.mouse_per_screen then
|
||||
-- This is the first time we enter this screen,
|
||||
-- keep relative mouse position on the new screen.
|
||||
|
@ -115,6 +121,7 @@ function screen.focus(_screen)
|
|||
-- restore mouse position
|
||||
pos = _screen.mouse_per_screen
|
||||
end
|
||||
end
|
||||
|
||||
-- save pointer position of current screen
|
||||
s.mouse_per_screen = capi.mouse.coords()
|
||||
|
|
Loading…
Reference in New Issue