2009-08-19 11:21:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @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")
|
|
|
|
|
2011-01-27 18:10:39 +01:00
|
|
|
-- Give focus when clients appear/disappear.
|
2009-08-19 11:21:56 +02:00
|
|
|
-- @param obj An object that should have a .screen property.
|
|
|
|
local function check_focus(obj)
|
2011-01-27 18:10:39 +01:00
|
|
|
-- When no visible client has the focus...
|
2009-08-19 11:21:56 +02:00
|
|
|
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
|
2011-01-27 18:10:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Give focus on tag selection change.
|
|
|
|
-- @param obj An object that should have a .screen property.
|
|
|
|
local function check_focus_screen(obj)
|
|
|
|
check_focus(obj)
|
|
|
|
if client.focus and client.focus.screen ~= obj.screen then
|
|
|
|
local c = nil
|
|
|
|
c = aclient.focus.history.get(obj.screen, 0)
|
2010-01-09 17:23:05 +01:00
|
|
|
if c then client.focus = c end
|
2009-08-19 11:21:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-27 18:10:39 +01:00
|
|
|
atag.attached_add_signal(nil, "property::selected", check_focus_screen)
|
2009-08-19 11:21:56 +02:00
|
|
|
client.add_signal("unmanage", check_focus)
|
|
|
|
client.add_signal("new", function(c)
|
2011-04-16 16:00:35 +02:00
|
|
|
c:add_signal("tagged", check_focus)
|
2009-08-19 11:21:56 +02:00
|
|
|
c:add_signal("untagged", check_focus)
|
2009-08-24 23:10:55 +02:00
|
|
|
c:add_signal("property::hidden", check_focus)
|
|
|
|
c:add_signal("property::minimized", check_focus)
|
2009-08-19 11:21:56 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|