awesome/lib/awful/autofocus.lua.in

41 lines
1.5 KiB
Lua

---------------------------------------------------------------------------
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2009 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
local client = client
local screen = screen
local aclient = require("awful.client")
local atag = require("awful.tag")
--- When loaded, this module makes sure that there's always a client that will have focus
-- on event such as tag switching, client unmanaging, etc.
module("awful.autofocus")
-- Give focus on tag selection change.
-- @param obj An object that should have a .screen property.
local function check_focus(obj)
if not client.focus or not client.focus:isvisible() then
local c = aclient.focus.history.get(obj.screen, 0)
if c then client.focus = c end
end
-- If we didn't find a client, try other screens.
if not client.focus or not client.focus:isvisible() then
for i = 1, screen.count() do
local c = aclient.focus.history.get(i, 0)
if c and c:isvisible() then client.focus = c; return end
end
end
end
atag.attached_add_signal(nil, "property::selected", check_focus)
client.add_signal("unmanage", check_focus)
client.add_signal("new", function(c)
c:add_signal("untagged", check_focus)
c:add_signal("property::hidden", check_focus)
c:add_signal("property::minimized", check_focus)
end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80