From 71c0ded9400be52d85a293b2beb1785c8a165019 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 2 May 2009 10:43:55 +0200 Subject: [PATCH] tag: add a hook for tag on select/unselect Signed-off-by: Julien Danjou --- awesomerc.lua.in | 7 +++---- hooks.c | 3 ++- tag.c | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index d0c3c27ba..e39b2b1c8 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -406,9 +406,8 @@ awful.hooks.manage.register(function (c, startup) -- c.size_hints_honor = false end) --- Hook function to execute when arranging the screen. --- (tag switch, new client, etc) -awful.hooks.arrange.register(function (screen) +-- Hook function to execute when switching tag selection. +awful.hooks.tags.register(function (screen, tag, view) local layout = awful.layout.getname(awful.layout.get(screen)) if layout and beautiful["layout_" ..layout] then mylayoutbox[screen].image = image(beautiful["layout_" .. layout]) @@ -418,7 +417,7 @@ awful.hooks.arrange.register(function (screen) -- 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 then + 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 diff --git a/hooks.c b/hooks.c index af8e51a3b..7ca241f80 100644 --- a/hooks.c +++ b/hooks.c @@ -123,7 +123,8 @@ luaA_hooks_clients(lua_State *L) /** Set the function called on each screen tag list change. * This function is called with a screen number as first argument, - * the tag object as second and the action (add or remove) as third. + * the tag object as second and the action (add, remove, select or unselect) + * as third. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack diff --git a/tag.c b/tag.c index 96589d5e7..8b779d469 100644 --- a/tag.c +++ b/tag.c @@ -54,10 +54,22 @@ luaA_tag_gc(lua_State *L) static void tag_view(tag_t *tag, bool view) { + int screen_index = screen_array_indexof(&globalconf.screens, tag->screen); + tag->selected = view; - ewmh_update_net_current_desktop(screen_virttophys(screen_array_indexof(&globalconf.screens, - tag->screen))); tag->screen->need_arrange = true; + ewmh_update_net_current_desktop(screen_virttophys(screen_index)); + + if(globalconf.hooks.tags != LUA_REFNIL) + { + lua_pushnumber(globalconf.L, screen_index + 1); + tag_push(globalconf.L, tag); + if(view) + lua_pushliteral(globalconf.L, "select"); + else + lua_pushliteral(globalconf.L, "unselect"); + luaA_dofunction(globalconf.L, globalconf.hooks.tags, 3, 0); + } } /** Append a tag which on top of the stack to a screen.