Add request::focus signal, with ewmh.focus being the default handler

This still does `client.focus = c` by default, but allows to customize
it.

This was initially suggested in #194, but by using `request::activate`
instead, which would not be the same.  Therefore a new signal is being
used instead.

Helped-by: Samir Benmendil <samir.benmendil@gmail.com>
This commit is contained in:
Daniel Hahler 2015-05-13 13:36:28 +02:00
parent cec04b2684
commit 401f21f8e2
5 changed files with 24 additions and 9 deletions

View File

@ -71,7 +71,7 @@ function client.jumpto(c, merge)
end
-- focus the client
capi.client.focus = c
c:emit_signal("request::focus", "client.jumpto")
c:raise()
end
@ -213,7 +213,9 @@ 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::focus", "client.focus.history.previous")
end
end
--- Get visible clients from a screen.
@ -303,7 +305,7 @@ 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::focus", "client.focus.bydirection")
end
end
end
@ -335,7 +337,7 @@ 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::focus", "client.focus.global_bydirection")
end
end
end
@ -348,7 +350,7 @@ end
function client.focus.byidx(i, c)
local target = client.next(i, c)
if target then
capi.client.focus = target
target:emit_signal("request::focus", "client.focus.byidx")
end
end
@ -403,7 +405,7 @@ function client.swap.global_bydirection(dir, c)
end
screen.focus(sel.screen)
capi.client.focus = sel
sel:emit_signal("request::focus", "client.swap.global_bydirection")
end
end

View File

@ -165,6 +165,14 @@ function ewmh.activate(c)
end
end
--- Focus a window.
--
-- @client c The client.
-- @tparam string context The context where this signal was used.
function ewmh.focus(c, context)
client.focus = c
end
--- Tag a window with its requested tag
--
-- @client c A client to tag
@ -185,6 +193,7 @@ function ewmh.urgent(c, urgent)
end
client.connect_signal("request::activate", ewmh.activate)
client.connect_signal("request::focus", ewmh.focus)
client.connect_signal("request::tag", ewmh.tag)
client.connect_signal("request::urgent", ewmh.urgent)
client.connect_signal("request::maximized_horizontal", maximized_horizontal)

View File

@ -178,7 +178,9 @@ 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::focus", "layout.arrange_on_tagged")
end
end
end
local function arrange_tag(t)

View File

@ -476,7 +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:emit_signal("request::focus", "menu.clients")
c:raise()
end,
c.icon }

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::focus", "screen.focus")
end
end
--- Give the focus to a screen, and move pointer, by physical position relative to current screen.