hooks: add clients hook

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-20 15:01:16 +02:00
parent 1f4df91c30
commit ba66ae8035
4 changed files with 36 additions and 8 deletions

View File

@ -456,8 +456,8 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
} }
/* Push client in client list */ /* Push client in client list */
client_list_push(&globalconf.clients, c); client_list_push(&globalconf.clients, client_ref(&c));
client_ref(&c);
/* Push client in stack */ /* Push client in stack */
client_raise(c); 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); ewmh_update_net_client_list(c->phys_screen);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); 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 */ /* call hook */
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0); 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) if(globalconf.screens[c->phys_screen].client_focus == c)
client_unfocus(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 */ /* call hook */
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0); 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. */ /* The server grab construct avoids race conditions. */
xcb_grab_server(globalconf.connection); xcb_grab_server(globalconf.connection);
@ -833,12 +845,6 @@ client_unmanage(client_t *c)
xcb_flush(globalconf.connection); xcb_flush(globalconf.connection);
xcb_ungrab_server(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); titlebar_client_detach(c);
ewmh_update_net_client_list(c->phys_screen); ewmh_update_net_client_list(c->phys_screen);
@ -1035,6 +1041,10 @@ luaA_client_swap(lua_State *L)
client_need_arrange(*swap); client_need_arrange(*swap);
widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
widget_invalidate_cache((*swap)->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; return 0;
} }

15
luaa.c
View File

@ -218,6 +218,19 @@ luaA_hooks_mouse_over(lua_State *L)
return luaA_hooks_mouse_enter(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 /** Set the function called on each screen arrange. This function is called
* with the screen number as argument. * with the screen number as argument.
* \param L The Lua VM state. * \param L The Lua VM state.
@ -611,6 +624,7 @@ luaA_init(void)
{ "mouse_enter", luaA_hooks_mouse_enter }, { "mouse_enter", luaA_hooks_mouse_enter },
{ "property", luaA_hooks_property }, { "property", luaA_hooks_property },
{ "arrange", luaA_hooks_arrange }, { "arrange", luaA_hooks_arrange },
{ "clients", luaA_hooks_clients },
{ "timer", luaA_hooks_timer }, { "timer", luaA_hooks_timer },
/* deprecated */ /* deprecated */
{ "mouse_over", luaA_hooks_mouse_over }, { "mouse_over", luaA_hooks_mouse_over },
@ -686,6 +700,7 @@ luaA_init(void)
globalconf.hooks.unfocus = LUA_REFNIL; globalconf.hooks.unfocus = LUA_REFNIL;
globalconf.hooks.mouse_enter = LUA_REFNIL; globalconf.hooks.mouse_enter = LUA_REFNIL;
globalconf.hooks.arrange = LUA_REFNIL; globalconf.hooks.arrange = LUA_REFNIL;
globalconf.hooks.clients = LUA_REFNIL;
globalconf.hooks.property = LUA_REFNIL; globalconf.hooks.property = LUA_REFNIL;
globalconf.hooks.timer = LUA_REFNIL; globalconf.hooks.timer = LUA_REFNIL;
} }

View File

@ -551,6 +551,7 @@ mouse_client_move(client_t *c, int snap, bool infobox)
{ {
client_list_swap(&globalconf.clients, c, target); client_list_swap(&globalconf.clients, c, target);
globalconf.screens[c->screen].need_arrange = true; globalconf.screens[c->screen].need_arrange = true;
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
layout_refresh(); layout_refresh();
wibox_refresh(); wibox_refresh();
xcb_flush(globalconf.connection); xcb_flush(globalconf.connection);

View File

@ -435,6 +435,8 @@ struct awesome_t
luaA_ref mouse_enter; luaA_ref mouse_enter;
/** Command to run on arrange */ /** Command to run on arrange */
luaA_ref arrange; luaA_ref arrange;
/** Command to run when client list changes */
luaA_ref clients;
/** Command to run on property change */ /** Command to run on property change */
luaA_ref property; luaA_ref property;
/** Command to run on time */ /** Command to run on time */