Merge pull request #224 from blueyed/request-focus-signal

Add 'request::focus' signal, use it with autofocus
This commit is contained in:
Daniel Hahler 2015-06-25 07:00:22 +02:00
commit 33a6ade4d7
10 changed files with 47 additions and 28 deletions

View File

@ -161,11 +161,9 @@ mytasklist.buttons = awful.util.table.join(
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end))
for s = 1, screen.count() do
@ -229,12 +227,10 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "k",
function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "w", function () mymainmenu:show() end),

View File

@ -55,7 +55,6 @@ file = {
-- documentation
'../lib/awful/autofocus.lua',
'../lib/awful/dbus.lua',
'../lib/awful/ewmh.lua',
'../lib/awful/init.lua',
'../lib/awful/remote.lua',
'../lib/awful/startup_notification.lua',

9
ewmh.c
View File

@ -430,7 +430,14 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
lua_State *L = globalconf_get_lua_State();
luaA_object_push(L, c);
lua_pushstring(L, "ewmh");
luaA_object_emit_signal(L, -2, "request::activate", 1);
/* Create table argument with raise=true. */
lua_newtable(L);
lua_pushstring(L, "raise");
lua_pushboolean(L, true);
lua_settable(L, -3);
luaA_object_emit_signal(L, -3, "request::activate", 2);
lua_pop(L, 1);
}
}

View File

@ -24,7 +24,8 @@ local function check_focus(obj)
if not client.focus or not client.focus:isvisible() then
local c = aclient.focus.history.get(obj.screen, 0, aclient.focus.filter)
if c then
c:emit_signal('request::activate', "autofocus.check_focus")
c:emit_signal("request::activate", "autofocus.check_focus",
{raise=false})
end
end
end
@ -45,7 +46,8 @@ local function check_focus_tag(t)
if client.focus and client.focus.screen ~= s then
local c = aclient.focus.history.get(s, 0, aclient.focus.filter)
if c then
c:emit_signal('request::activate', "autofocus.check_focus_tag")
c:emit_signal("request::activate", "autofocus.check_focus_tag",
{raise=false})
end
end
end

View File

@ -70,9 +70,7 @@ function client.jumpto(c, merge)
end
end
-- focus the client
capi.client.focus = c
c:raise()
c:emit_signal("request::activate", "client.jumpto", {raise=true})
end
--- Get the first client that got the urgent hint.
@ -213,7 +211,10 @@ function client.focus.history.previous()
s = capi.mouse.screen
end
local c = client.focus.history.get(s, 1)
if c then capi.client.focus = c end
if c then
c:emit_signal("request::activate", "client.focus.history.previous",
{raise=false})
end
end
--- Get visible clients from a screen.
@ -303,7 +304,8 @@ function client.focus.bydirection(dir, c)
-- If we found a client to focus, then do it.
if target then
capi.client.focus = cltbl[target]
cltbl[target]:emit_signal("request::activate",
"client.focus.bydirection", {raise=false})
end
end
end
@ -335,7 +337,9 @@ function client.focus.global_bydirection(dir, c)
local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[scr].geometry)
if target then
capi.client.focus = cltbl[target]
cltbl[target]:emit_signal("request::activate",
"client.focus.global_bydirection",
{raise=false})
end
end
end
@ -348,7 +352,8 @@ end
function client.focus.byidx(i, c)
local target = client.next(i, c)
if target then
capi.client.focus = target
target:emit_signal("request::activate", "client.focus.byidx",
{raise=true})
end
end
@ -396,14 +401,15 @@ function client.swap.global_bydirection(dir, c)
elseif sel.screen ~= c.screen and sel == c then
client.movetoscreen(sel, capi.mouse.screen)
--swapping to a nonempty screen
-- swapping to a nonempty screen
elseif sel.screen ~= c.screen and sel ~= c then
client.movetoscreen(sel, c.screen)
client.movetoscreen(c, scr)
end
screen.focus(sel.screen)
capi.client.focus = sel
sel:emit_signal("request::activate", "client.swap.global_bydirection",
{raise=false})
end
end

View File

@ -156,13 +156,18 @@ end
--- Activate a window
--
-- @client c A client to use
function ewmh.activate(c)
if awesome.startup or c:isvisible() then
-- @tparam string context The context where this signal was used.
-- @tparam table hints A table with additional hints:
-- @tparam boolean hints.raise should the client be raised? (default false)
function ewmh.activate(c, context, hints)
client.focus = c
if raise then
if awesome.startup or c:isvisible() then
c:raise()
else
c.urgent = true
end
end
end
--- Tag a window with its requested tag

View File

@ -178,7 +178,10 @@ local function arrange_on_tagged(c, tag)
layout.arrange(tag.screen)
if not capi.client.focus or not capi.client.focus:isvisible() then
local c = client.focus.history.get(tag.screen, 0)
if c then capi.client.focus = c end
if c then
c:emit_signal("request::activate", "layout.arrange_on_tagged",
{raise=false})
end
end
end
local function arrange_tag(t)

View File

@ -476,8 +476,7 @@ function menu.clients(args, item_args)
if not c:isvisible() then
tags.viewmore(c:tags(), c.screen)
end
capi.client.focus = c
c:raise()
c:emit_signal("request::activate", "menu.clients", {raise=true})
end,
c.icon }
if item_args then

View File

@ -217,7 +217,7 @@ function rules.execute(c, props, callbacks)
-- Do this at last so we do not erase things done by the focus
-- signal.
if props.focus and (type(props.focus) ~= "function" or props.focus(c)) then
c:emit_signal('request::activate',"rules")
c:emit_signal('request::activate', "rules", {raise=false})
end
end

View File

@ -66,7 +66,9 @@ function screen.focus(_screen)
capi.mouse.coords(pos, true)
local c = client.focus.history.get(_screen, 0)
if c then capi.client.focus = c end
if c then
c:emit_signal("request::activate", "screen.focus", {raise=false})
end
end
--- Give the focus to a screen, and move pointer, by physical position relative to current screen.