diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 18860e5c..18c1cae0 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -1,5 +1,6 @@ -- Standard awesome library require("awful") +require("awful.autofocus") -- Theme handling library require("beautiful") -- Notification library @@ -377,15 +378,4 @@ client.add_signal("manage", function (c, startup) -- Honor size hints: if you want to drop the gaps between windows, set this to false. -- c.size_hints_honor = false end) - --- Hook function to execute when switching tag selection. -awful.hooks.tags.register(function (screen, tag, view) - -- Give focus to the latest client in history if no window has focus - -- or if the current window is a desktop or a dock one. - if not client.focus or not client.focus:isvisible() then - local c = awful.client.focus.history.get(screen, 0) - if c then client.focus = c end - end -end) - -- }}} diff --git a/lib/awful/autofocus.lua.in b/lib/awful/autofocus.lua.in new file mode 100644 index 00000000..b7a04c85 --- /dev/null +++ b/lib/awful/autofocus.lua.in @@ -0,0 +1,31 @@ +--------------------------------------------------------------------------- +-- @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 +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) +end) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80