Skip to content

Commit

Permalink
Improve moving/restoring mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Apr 2, 2017
1 parent 8b37907 commit 1c481e0
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ local raise_client = function(c)
if t then
t:view_only()
end
c:raise()
c:jump_to()
end


Expand Down Expand Up @@ -771,11 +771,15 @@ cyclefocus.cycle = function(startdirection_or_args, args)
local initial_screen = awful.screen.focused and awful.screen.focused() or mouse.screen

-- Move mouse pointer away to avoid sloppy focus kicking in.
-- TODO: go to current screen's 0/0 (not total). Have an option/method for this!
local restore_mouse_coords
if show_clients then
restore_mouse_coords = capi.mouse.coords()
capi.mouse.coords({ x = 0, y = 0 }, true)
local s = capi.screen[capi.mouse.screen]
local coords = capi.mouse.coords()
restore_mouse_coords = {s = s, x = coords.x, y = coords.y}
local pos = {x = s.geometry.x, y = s.geometry.y}
-- move cursor without triggering signals mouse::enter and mouse::leave
capi.mouse.coords(pos, true)
restore_mouse_coords.moved = pos
end

capi.keygrabber.run(function(mod, key, event)
Expand All @@ -792,23 +796,25 @@ cyclefocus.cycle = function(startdirection_or_args, args)
if show_clients then
show_clients()
end

-- Restore mouse if it has not been moved during cycling.
if restore_mouse_coords then
if restore_mouse_coords.s == capi.screen[capi.mouse.screen] then
local coords = capi.mouse.coords()
local moved_coords = restore_mouse_coords.moved
if moved_coords.x == coords.x and moved_coords.y == coords.y then
capi.mouse.coords({x = restore_mouse_coords.x, y = restore_mouse_coords.y}, true)
end
end
end

if c then
showing_client = c
-- NOTE: awful.client.jumpto(c) resets mouse.
capi.client.focus = c
raise_client(c)
if c ~= orig_client then
history.movetotop(c)
end
end

-- Restore mouse if it has not been moved during cycling.
if restore_mouse_coords then
local coords = capi.mouse.coords()
if coords.x == 0 and coords.y == 0 then
capi.mouse.coords(restore_mouse_coords, true)
end
end
ignore_focus_signal = false

return true
Expand Down

0 comments on commit 1c481e0

Please sign in to comment.