diff --git a/client.c b/client.c index e4947e82..600fb0b9 100644 --- a/client.c +++ b/client.c @@ -456,8 +456,8 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, } /* Push client in client list */ - client_list_push(&globalconf.clients, c); - client_ref(&c); + client_list_push(&globalconf.clients, client_ref(&c)); + /* Push client in stack */ client_raise(c); @@ -470,6 +470,9 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, ewmh_update_net_client_list(c->phys_screen); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); + /* Call hook to notify list change */ + luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0); + /* call hook */ luaA_client_userdata_new(globalconf.L, c); luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0); @@ -815,10 +818,19 @@ client_unmanage(client_t *c) if(globalconf.screens[c->phys_screen].client_focus == c) client_unfocus(c); + /* remove client everywhere */ + client_list_detach(&globalconf.clients, c); + stack_client_delete(c); + for(int i = 0; i < tags->len; i++) + untag_client(c, tags->tab[i]); + /* call hook */ luaA_client_userdata_new(globalconf.L, c); luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0); + /* Call hook to notify list change */ + luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0); + /* The server grab construct avoids race conditions. */ xcb_grab_server(globalconf.connection); @@ -833,12 +845,6 @@ client_unmanage(client_t *c) xcb_flush(globalconf.connection); xcb_ungrab_server(globalconf.connection); - /* remove client everywhere */ - client_list_detach(&globalconf.clients, c); - stack_client_delete(c); - for(int i = 0; i < tags->len; i++) - untag_client(c, tags->tab[i]); - titlebar_client_detach(c); ewmh_update_net_client_list(c->phys_screen); @@ -1035,6 +1041,10 @@ luaA_client_swap(lua_State *L) client_need_arrange(*swap); widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache((*swap)->screen, WIDGET_CACHE_CLIENTS); + + /* Call hook to notify list change */ + luaA_dofunction(L, globalconf.hooks.clients, 0, 0); + return 0; } diff --git a/luaa.c b/luaa.c index fe7f2ea7..eee436aa 100644 --- a/luaa.c +++ b/luaa.c @@ -218,6 +218,19 @@ luaA_hooks_mouse_over(lua_State *L) return luaA_hooks_mouse_enter(L); } +/** Set the function called on each client list change. + * This function is called without any argument. + * \param L The Lua VM state. + * \return The number of elements pushed on stack. + * \luastack + * \lparam A function to call on each client list change. + */ +static int +luaA_hooks_clients(lua_State *L) +{ + return luaA_registerfct(L, 1, &globalconf.hooks.clients); +} + /** Set the function called on each screen arrange. This function is called * with the screen number as argument. * \param L The Lua VM state. @@ -611,6 +624,7 @@ luaA_init(void) { "mouse_enter", luaA_hooks_mouse_enter }, { "property", luaA_hooks_property }, { "arrange", luaA_hooks_arrange }, + { "clients", luaA_hooks_clients }, { "timer", luaA_hooks_timer }, /* deprecated */ { "mouse_over", luaA_hooks_mouse_over }, @@ -686,6 +700,7 @@ luaA_init(void) globalconf.hooks.unfocus = LUA_REFNIL; globalconf.hooks.mouse_enter = LUA_REFNIL; globalconf.hooks.arrange = LUA_REFNIL; + globalconf.hooks.clients = LUA_REFNIL; globalconf.hooks.property = LUA_REFNIL; globalconf.hooks.timer = LUA_REFNIL; } diff --git a/mouse.c b/mouse.c index 68151dab..c80c4255 100644 --- a/mouse.c +++ b/mouse.c @@ -551,6 +551,7 @@ mouse_client_move(client_t *c, int snap, bool infobox) { client_list_swap(&globalconf.clients, c, target); globalconf.screens[c->screen].need_arrange = true; + luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0); layout_refresh(); wibox_refresh(); xcb_flush(globalconf.connection); diff --git a/structs.h b/structs.h index 650722ff..5de9a4b4 100644 --- a/structs.h +++ b/structs.h @@ -435,6 +435,8 @@ struct awesome_t luaA_ref mouse_enter; /** Command to run on arrange */ luaA_ref arrange; + /** Command to run when client list changes */ + luaA_ref clients; /** Command to run on property change */ luaA_ref property; /** Command to run on time */