autofocus: use focus.filter, via new arg to focus.history.get

This adds an optional `filter` arg to awful.client.focus.history.get,
and uses `awful.client.focus.filter` from the autofocus module.

This improves the behaviour when manually setting clients as
non-focusable (#237), and is considered to be the desired behaviour in
general.

Closes https://github.com/awesomeWM/awesome/pull/242.
This commit is contained in:
Daniel Hahler 2015-05-25 15:23:30 +02:00
parent fd6ffb1458
commit 496fce0f90
2 changed files with 20 additions and 14 deletions

View File

@ -22,7 +22,7 @@ local timer = require("gears.timer")
local function check_focus(obj) local function check_focus(obj)
-- When no visible client has the focus... -- When no visible client has the focus...
if not client.focus or not client.focus:isvisible() then if not client.focus or not client.focus:isvisible() then
local c = aclient.focus.history.get(obj.screen, 0) local c = aclient.focus.history.get(obj.screen, 0, aclient.focus.filter)
if c then if c then
c:emit_signal('request::activate', "autofocus.check_focus") c:emit_signal('request::activate', "autofocus.check_focus")
end end
@ -43,7 +43,7 @@ local function check_focus_tag(t)
if not s then return end if not s then return end
check_focus({ screen = s }) check_focus({ screen = s })
if client.focus and client.focus.screen ~= s then if client.focus and client.focus.screen ~= s then
local c = aclient.focus.history.get(s, 0) local c = aclient.focus.history.get(s, 0, aclient.focus.filter)
if c then if c then
c:emit_signal('request::activate', "autofocus.check_focus_tag") c:emit_signal('request::activate', "autofocus.check_focus_tag")
end end

View File

@ -164,16 +164,20 @@ end
--- Get the latest focused client for a screen in history. --- Get the latest focused client for a screen in history.
-- --
-- @param screen The screen number to look for. -- @tparam int screen The screen number to look for.
-- @param idx The index: 0 will return first candidate, -- @tparam int idx The index: 0 will return first candidate,
-- 1 will return second, etc. -- 1 will return second, etc.
-- @return A client. -- @tparam function An optional filter. If no client is found in the first
function client.focus.history.get(screen, idx) -- iteration, client.focus.filter is used by default to get
-- any client.
-- @treturn client A client.
function client.focus.history.get(screen, idx, filter)
-- When this counter is equal to idx, we return the client -- When this counter is equal to idx, we return the client
local counter = 0 local counter = 0
local vc = client.visible(screen) local vc = client.visible(screen)
for k, c in ipairs(client.data.focus) do for k, c in ipairs(client.data.focus) do
if c.screen == screen then if c.screen == screen then
if not filter or filter(c) then
for j, vcc in ipairs(vc) do for j, vcc in ipairs(vc) do
if vcc == c then if vcc == c then
if counter == idx then if counter == idx then
@ -186,11 +190,13 @@ function client.focus.history.get(screen, idx)
end end
end end
end end
end
-- Argh nobody found in history, give the first one visible if there is one -- Argh nobody found in history, give the first one visible if there is one
-- that passes the filter. -- that passes the filter.
local filter = filter or client.focus.filter
if counter == 0 then if counter == 0 then
for k, v in ipairs(vc) do for k, v in ipairs(vc) do
if client.focus.filter(v) then if filter(v) then
return v return v
end end
end end