From 4573147196d333b1b28082aec6d47632b70aad19 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 10 Jun 2008 19:03:10 +0200 Subject: [PATCH] [hooks] Rename newclient to `manage', add unmanage hook Signed-off-by: Julien Danjou --- awesomerc.lua.in | 4 ++-- client.c | 6 +++++- lua.c | 37 ++++++++++++++++++++++++++++++------- structs.h | 4 +++- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index ddf3c51a5..e0b3ae61b 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -203,7 +203,7 @@ function hook_mouseover(c) end -- Hook function to execute when a new client appears. -function hook_newclient(c) +function hook_manage(c) -- New client may not receive focus -- if they're not focusable, so set border anyway. c:border_set({ width = 1, color = "black" }) @@ -231,7 +231,7 @@ end -- Set up some hooks awful.hooks.focus(hook_focus) awful.hooks.unfocus(hook_unfocus) -awful.hooks.newclient(hook_newclient) +awful.hooks.manage(hook_manage) awful.hooks.mouseover(hook_mouseover) awful.hooks.arrange(hook_arrange) awful.hooks.timer(1, hook_timer) diff --git a/client.c b/client.c index 3848ce3fe..0f4941f46 100644 --- a/client.c +++ b/client.c @@ -414,7 +414,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen) /* call hook */ luaA_client_userdata_new(c); - luaA_dofunction(globalconf.L, globalconf.hooks.newclient, 1); + luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1); } static area_t @@ -629,6 +629,10 @@ client_unmanage(client_t *c) { tag_t *tag; + /* call hook */ + luaA_client_userdata_new(c); + luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1); + /* The server grab construct avoids race conditions. */ xcb_grab_server(globalconf.connection); diff --git a/lua.c b/lua.c index d7941d5b0..696e621b4 100644 --- a/lua.c +++ b/lua.c @@ -251,16 +251,38 @@ luaA_hooks_unfocus(lua_State *L) } /** Set the function called each time a new client appears. This function is - * called with the client object as argument - * \param A function to call on each new client. + * called with the client object as argument. + * \param L The Lua VM state. + * + * \luastack + * + * \lparam A function to call on each new client. */ static int -luaA_hooks_newclient(lua_State *L) +luaA_hooks_manage(lua_State *L) { luaA_checkfunction(L, 1); - if(globalconf.hooks.newclient) - luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.newclient); - globalconf.hooks.newclient = luaL_ref(L, LUA_REGISTRYINDEX); + if(globalconf.hooks.manage) + luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.manage); + globalconf.hooks.manage = luaL_ref(L, LUA_REGISTRYINDEX); + return 0; +} + +/** Set the function called each time a client goes away. This function is + * called with the client object as argument. + * \param L The Lua VM state. + * + * \luastack + * + * \lparam A function to call on each new client. + */ +static int +luaA_hooks_unmanage(lua_State *L) +{ + luaA_checkfunction(L, 1); + if(globalconf.hooks.unmanage) + luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.unmanage); + globalconf.hooks.unmanage = luaL_ref(L, LUA_REGISTRYINDEX); return 0; } @@ -434,7 +456,8 @@ luaA_init(void) { { "focus", luaA_hooks_focus }, { "unfocus", luaA_hooks_unfocus }, - { "newclient", luaA_hooks_newclient }, + { "manage", luaA_hooks_manage }, + { "unmanage", luaA_hooks_unmanage }, { "mouseover", luaA_hooks_mouseover }, { "arrange", luaA_hooks_arrange }, { "titleupdate", luaA_hooks_titleupdate }, diff --git a/structs.h b/structs.h index b3b805219..4ec6d7b35 100644 --- a/structs.h +++ b/structs.h @@ -426,7 +426,9 @@ struct awesome_t struct { /** Command to execute when spawning a new client */ - luaA_function newclient; + luaA_function manage; + /** Command to execute when unmanaging client */ + luaA_function unmanage; /** Command to execute when giving focus to a client */ luaA_function focus; /** Command to execute when removing focus to a client */