signals: better handling of sloppy focus and mouse follows focus

It may happend that a client is focused on `mouse::enter` without the
`focus` event being fired. Therefore, the next client to be focused
will not get the mouse on its top left corner because we think that
the focus comes from sloppy focus.

We circumvent this by:
 1. giving sloppy focus only if we don't have focus
 2. keeping track of the client getting the focus through sloppy focus
    and checking it if we get the same client on focus event
This commit is contained in:
Vincent Bernat 2012-07-31 20:43:21 +02:00
parent c8e9e2512d
commit 79cd569c33

View file

@ -20,13 +20,19 @@ client.add_signal("manage",
-- Enable sloppy focus -- Enable sloppy focus
c:add_signal("mouse::enter", c:add_signal("mouse::enter",
function(c) function(c)
if ((awful.layout.get(c.screen) ~= awful.layout.suit.magnifier or awful.client.getmaster(c.screen) == c) -- If magnifier suit, only give sloppy focus to master window
if ((awful.layout.get(c.screen) ~= awful.layout.suit.magnifier or
awful.client.getmaster(c.screen) == c)
-- Don't give focus to a client already having focus
and client.focus ~= c
-- Don't give focus to a window that does not want focus
and awful.client.focus.filter(c)) then and awful.client.focus.filter(c)) then
focus_from_mouse = true focus_from_mouse = c
client.focus = c client.focus = c
end end
end) end)
-- If a window change its geometry, track it with the mouse
c:add_signal("property::geometry", c:add_signal("property::geometry",
function() function()
if client.focus == c then if client.focus == c then
@ -56,7 +62,7 @@ client.add_signal("focus", function(c)
c.border_color = beautiful.border_focus c.border_color = beautiful.border_focus
c.opacity = 1 c.opacity = 1
if not focus_from_mouse then if focus_from_mouse ~= c then
mouse_follow_focus(c) mouse_follow_focus(c)
end end
focus_from_mouse = false focus_from_mouse = false