From 401f21f8e216337a3e94e77db64e55aa7c86c803 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 13 May 2015 13:36:28 +0200 Subject: [PATCH 1/6] 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 --- lib/awful/client.lua | 14 ++++++++------ lib/awful/ewmh.lua | 9 +++++++++ lib/awful/layout/init.lua | 4 +++- lib/awful/menu.lua | 2 +- lib/awful/screen.lua | 4 +++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 6f206f1c..a698a984 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -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 diff --git a/lib/awful/ewmh.lua b/lib/awful/ewmh.lua index 6d542dbc..d7551fdf 100644 --- a/lib/awful/ewmh.lua +++ b/lib/awful/ewmh.lua @@ -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) diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index cf55cfd5..10faa9f9 100755 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -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) diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index 821db869..bc9bcb38 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -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 } diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 1414d39b..0b5e3483 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -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. From 6dc355cf716beca1e545d6ef8ebe1d422b0064b5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 13 May 2015 13:06:53 +0200 Subject: [PATCH 2/6] autofocus: use request::focus instead of request::activate In #152 I've changed the autofocus handler to emit the request::activate signal, instead of setting client.focus only. This is wrong IMHO, and can be annoying: If you have two floating clients above a tiled / maximized one, and close one of the floating ones, with the tiled one being the one selected by autofocus, it will be raised above the other floating client. This is changed now to use the new `request::focus` signal instead. This basically reverts 20cdb5d (#152), but allows for customizing this behavior, by overriding the default `request::focus` handler (`ewmh.focus`). It would be nice if there was a helper to check if a window's content isn't visible at all (i.e. covered by other windows), and that could be used then by the (new) default handler for request::focus - raising the client only, if it's completely covered by another window. Fixes https://github.com/awesomeWM/awesome/issues/217 --- lib/awful/autofocus.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/awful/autofocus.lua b/lib/awful/autofocus.lua index 325acb36..2f0c89f8 100644 --- a/lib/awful/autofocus.lua +++ b/lib/awful/autofocus.lua @@ -24,7 +24,7 @@ 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::focus", "autofocus.check_focus") end end end @@ -45,7 +45,7 @@ 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::focus", "autofocus.check_focus_tag") end end end From ed09d8ed4ff73bd70b05802d52864d5ccacb7d13 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 13 May 2015 22:11:07 +0200 Subject: [PATCH 3/6] Use request::activate with raise=false instead Ref: https://github.com/awesomeWM/awesome/pull/224#issuecomment-101790416 --- ewmh.c | 3 ++- lib/awful/autofocus.lua | 4 ++-- lib/awful/client.lua | 14 ++++++-------- lib/awful/ewmh.lua | 23 +++++++++-------------- lib/awful/layout/init.lua | 2 +- lib/awful/menu.lua | 3 +-- lib/awful/rules.lua | 2 +- lib/awful/screen.lua | 2 +- 8 files changed, 23 insertions(+), 30 deletions(-) diff --git a/ewmh.c b/ewmh.c index 0a4a7b7c..c58dbbd6 100755 --- a/ewmh.c +++ b/ewmh.c @@ -430,7 +430,8 @@ 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); + lua_pushboolean(L, true); + luaA_object_emit_signal(L, -3, "request::activate", 2); lua_pop(L, 1); } } diff --git a/lib/awful/autofocus.lua b/lib/awful/autofocus.lua index 2f0c89f8..0e2556ff 100644 --- a/lib/awful/autofocus.lua +++ b/lib/awful/autofocus.lua @@ -24,7 +24,7 @@ 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::focus", "autofocus.check_focus") + c:emit_signal("request::activate", "autofocus.check_focus", false) end end end @@ -45,7 +45,7 @@ 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::focus", "autofocus.check_focus_tag") + c:emit_signal("request::activate", "autofocus.check_focus_tag", false) end end end diff --git a/lib/awful/client.lua b/lib/awful/client.lua index a698a984..b0914788 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -70,9 +70,7 @@ function client.jumpto(c, merge) end end - -- focus the client - c:emit_signal("request::focus", "client.jumpto") - c:raise() + c:emit_signal("request::activate", "client.jumpto", true) end --- Get the first client that got the urgent hint. @@ -214,7 +212,7 @@ function client.focus.history.previous() end local c = client.focus.history.get(s, 1) if c then - c:emit_signal("request::focus", "client.focus.history.previous") + c:emit_signal("request::activate", "client.focus.history.previous", false) end end @@ -305,7 +303,7 @@ function client.focus.bydirection(dir, c) -- If we found a client to focus, then do it. if target then - cltbl[target]:emit_signal("request::focus", "client.focus.bydirection") + cltbl[target]:emit_signal("request::activate", "client.focus.bydirection", false) end end end @@ -337,7 +335,7 @@ function client.focus.global_bydirection(dir, c) local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[scr].geometry) if target then - cltbl[target]:emit_signal("request::focus", "client.focus.global_bydirection") + cltbl[target]:emit_signal("request::activate", "client.focus.global_bydirection", false) end end end @@ -350,7 +348,7 @@ end function client.focus.byidx(i, c) local target = client.next(i, c) if target then - target:emit_signal("request::focus", "client.focus.byidx") + target:emit_signal("request::activate", "client.focus.byidx", false) end end @@ -405,7 +403,7 @@ function client.swap.global_bydirection(dir, c) end screen.focus(sel.screen) - sel:emit_signal("request::focus", "client.swap.global_bydirection") + sel:emit_signal("request::activate", "client.swap.global_bydirection", false) end end diff --git a/lib/awful/ewmh.lua b/lib/awful/ewmh.lua index d7551fdf..da05fc5d 100644 --- a/lib/awful/ewmh.lua +++ b/lib/awful/ewmh.lua @@ -156,21 +156,17 @@ end --- Activate a window -- -- @client c A client to use -function ewmh.activate(c) - if awesome.startup or c:isvisible() then - client.focus = c - c:raise() - else - c.urgent = true - end -end - ---- Focus a window. --- --- @client c The client. -- @tparam string context The context where this signal was used. -function ewmh.focus(c, context) +-- @tparam boolean raise Should the client be raised? +function ewmh.activate(c, context, raise) 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 @@ -193,7 +189,6 @@ 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) diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index 10faa9f9..924a4098 100755 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -179,7 +179,7 @@ local function arrange_on_tagged(c, tag) if not capi.client.focus or not capi.client.focus:isvisible() then local c = client.focus.history.get(tag.screen, 0) if c then - c:emit_signal("request::focus", "layout.arrange_on_tagged") + c:emit_signal("request::activate", "layout.arrange_on_tagged", false) end end end diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index bc9bcb38..5aca0cb3 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -476,8 +476,7 @@ function menu.clients(args, item_args) if not c:isvisible() then tags.viewmore(c:tags(), c.screen) end - c:emit_signal("request::focus", "menu.clients") - c:raise() + c:emit_signal("request::activate", "menu.clients", true) end, c.icon } if item_args then diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index a9df3a34..d87f20e9 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -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", false) end end diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 0b5e3483..d19bc3da 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -67,7 +67,7 @@ function screen.focus(_screen) local c = client.focus.history.get(_screen, 0) if c then - c:emit_signal("request::focus", "screen.focus") + c:emit_signal("request::activate", "screen.focus", false) end end From 2e2d60a1f994b6c701b23c72b4e10ad139a352a4 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 13 May 2015 22:39:38 +0200 Subject: [PATCH 4/6] client.focus.byidx: handle raising in the function itself --- awesomerc.lua | 4 ---- lib/awful/client.lua | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/awesomerc.lua b/awesomerc.lua index dff4265e..d8b90042 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -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), diff --git a/lib/awful/client.lua b/lib/awful/client.lua index b0914788..7fc60a03 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -348,7 +348,7 @@ end function client.focus.byidx(i, c) local target = client.next(i, c) if target then - target:emit_signal("request::activate", "client.focus.byidx", false) + target:emit_signal("request::activate", "client.focus.byidx", true) end end From b7e2508144d48bd9a9ea0d7e458fc64207ae2824 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 19 Jun 2015 22:19:04 +0200 Subject: [PATCH 5/6] docs: include lib/awful/ewmh.lua --- docs/config.ld | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/config.ld b/docs/config.ld index c47faf55..08679918 100644 --- a/docs/config.ld +++ b/docs/config.ld @@ -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', From cb7f4b06eb80f6e6ac6c54df50d1f6ded50b53ce Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 19 Jun 2015 22:24:12 +0200 Subject: [PATCH 6/6] Use `hints` table argument with `request::activate` signal --- ewmh.c | 6 ++++++ lib/awful/autofocus.lua | 6 ++++-- lib/awful/client.lua | 20 +++++++++++++------- lib/awful/ewmh.lua | 5 +++-- lib/awful/layout/init.lua | 3 ++- lib/awful/menu.lua | 2 +- lib/awful/rules.lua | 2 +- lib/awful/screen.lua | 2 +- 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ewmh.c b/ewmh.c index c58dbbd6..730edc18 100755 --- a/ewmh.c +++ b/ewmh.c @@ -430,7 +430,13 @@ 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"); + + /* 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); } diff --git a/lib/awful/autofocus.lua b/lib/awful/autofocus.lua index 0e2556ff..066c9f71 100644 --- a/lib/awful/autofocus.lua +++ b/lib/awful/autofocus.lua @@ -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", false) + 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", false) + c:emit_signal("request::activate", "autofocus.check_focus_tag", + {raise=false}) end end end diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 7fc60a03..52eab6a7 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -70,7 +70,7 @@ function client.jumpto(c, merge) end end - c:emit_signal("request::activate", "client.jumpto", true) + c:emit_signal("request::activate", "client.jumpto", {raise=true}) end --- Get the first client that got the urgent hint. @@ -212,7 +212,8 @@ function client.focus.history.previous() end local c = client.focus.history.get(s, 1) if c then - c:emit_signal("request::activate", "client.focus.history.previous", false) + c:emit_signal("request::activate", "client.focus.history.previous", + {raise=false}) end end @@ -303,7 +304,8 @@ function client.focus.bydirection(dir, c) -- If we found a client to focus, then do it. if target then - cltbl[target]:emit_signal("request::activate", "client.focus.bydirection", false) + 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 - cltbl[target]:emit_signal("request::activate", "client.focus.global_bydirection", false) + 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 - target:emit_signal("request::activate", "client.focus.byidx", true) + 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) - sel:emit_signal("request::activate", "client.swap.global_bydirection", false) + sel:emit_signal("request::activate", "client.swap.global_bydirection", + {raise=false}) end end diff --git a/lib/awful/ewmh.lua b/lib/awful/ewmh.lua index da05fc5d..d00e07c7 100644 --- a/lib/awful/ewmh.lua +++ b/lib/awful/ewmh.lua @@ -157,8 +157,9 @@ end -- -- @client c A client to use -- @tparam string context The context where this signal was used. --- @tparam boolean raise Should the client be raised? -function ewmh.activate(c, context, raise) +-- @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 diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index 924a4098..97b94a74 100755 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -179,7 +179,8 @@ local function arrange_on_tagged(c, tag) if not capi.client.focus or not capi.client.focus:isvisible() then local c = client.focus.history.get(tag.screen, 0) if c then - c:emit_signal("request::activate", "layout.arrange_on_tagged", false) + c:emit_signal("request::activate", "layout.arrange_on_tagged", + {raise=false}) end end end diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index 5aca0cb3..ab8d73ec 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -476,7 +476,7 @@ function menu.clients(args, item_args) if not c:isvisible() then tags.viewmore(c:tags(), c.screen) end - c:emit_signal("request::activate", "menu.clients", true) + c:emit_signal("request::activate", "menu.clients", {raise=true}) end, c.icon } if item_args then diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index d87f20e9..cba2644e 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -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", false) + c:emit_signal('request::activate', "rules", {raise=false}) end end diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index d19bc3da..58f1cc4e 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -67,7 +67,7 @@ function screen.focus(_screen) local c = client.focus.history.get(_screen, 0) if c then - c:emit_signal("request::activate", "screen.focus", false) + c:emit_signal("request::activate", "screen.focus", {raise=false}) end end