2009-08-19 11:21:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 13:02:39 +02:00
|
|
|
--- Autofocus functions.
|
|
|
|
--
|
|
|
|
-- When loaded, this module makes sure that there's always a client that will
|
|
|
|
-- have focus on events such as tag switching, client unmanaging, etc.
|
|
|
|
--
|
2009-08-19 11:21:56 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @module awful.autofocus
|
2009-08-19 11:21:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local client = client
|
|
|
|
local screen = screen
|
|
|
|
local aclient = require("awful.client")
|
|
|
|
local atag = require("awful.tag")
|
2015-02-13 02:35:24 +01:00
|
|
|
local timer = require("gears.timer")
|
2009-08-19 11:21:56 +02:00
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Give focus when clients appear/disappear.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
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
|
2015-05-25 15:23:30 +02:00
|
|
|
local c = aclient.focus.history.get(obj.screen, 0, aclient.focus.filter)
|
2015-02-24 15:33:49 +01:00
|
|
|
if c then
|
|
|
|
c:emit_signal('request::activate', "autofocus.check_focus")
|
|
|
|
end
|
2011-01-27 18:10:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Check client focus (delayed).
|
2015-02-13 02:35:24 +01:00
|
|
|
-- @param obj An object that should have a .screen property.
|
|
|
|
local function check_focus_delayed(obj)
|
|
|
|
timer.delayed_call(check_focus, {screen = obj.screen})
|
|
|
|
end
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Give focus on tag selection change.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2012-10-20 17:33:32 +02:00
|
|
|
-- @param tag A tag object
|
|
|
|
local function check_focus_tag(t)
|
|
|
|
local s = atag.getscreen(t)
|
|
|
|
if not s then return end
|
|
|
|
check_focus({ screen = s })
|
|
|
|
if client.focus and client.focus.screen ~= s then
|
2015-05-25 15:23:30 +02:00
|
|
|
local c = aclient.focus.history.get(s, 0, aclient.focus.filter)
|
2015-02-24 15:33:49 +01:00
|
|
|
if c then
|
|
|
|
c:emit_signal('request::activate', "autofocus.check_focus_tag")
|
|
|
|
end
|
2009-08-19 11:21:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-13 02:35:24 +01:00
|
|
|
tag.connect_signal("property::selected", function (t)
|
|
|
|
timer.delayed_call(check_focus_tag, t)
|
|
|
|
end)
|
|
|
|
client.connect_signal("unmanage", check_focus_delayed)
|
|
|
|
client.connect_signal("tagged", check_focus_delayed)
|
|
|
|
client.connect_signal("untagged", check_focus_delayed)
|
|
|
|
client.connect_signal("property::hidden", check_focus_delayed)
|
|
|
|
client.connect_signal("property::minimized", check_focus_delayed)
|
2009-08-19 11:21:56 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|