luaa: check that function is not NIL before pushing and calling

Otherwise we may push unused elements because dofunction() checked
_after_ if the function was nil, or not.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-11-20 17:48:23 +01:00
parent ee8bcd6c43
commit d1db6903fa
9 changed files with 137 additions and 74 deletions

View File

@ -161,8 +161,11 @@ client_unfocus(client_t *c)
globalconf.screens[c->phys_screen].client_focus = NULL; globalconf.screens[c->phys_screen].client_focus = NULL;
/* Call hook */ /* Call hook */
if(globalconf.hooks.unfocus != LUA_REFNIL)
{
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
}
ewmh_update_net_active_window(c->phys_screen); ewmh_update_net_active_window(c->phys_screen);
} }
@ -217,8 +220,11 @@ client_focus(client_t *c)
client_need_arrange(c); client_need_arrange(c);
/* execute hook */ /* execute hook */
if(globalconf.hooks.focus != LUA_REFNIL)
{
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus); luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
}
ewmh_update_net_active_window(c->phys_screen); ewmh_update_net_active_window(c->phys_screen);
} }
@ -491,12 +497,16 @@ 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);
/* Call hook to notify list change */ /* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0); luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
/* call hook */ /* call hook */
if(globalconf.hooks.manage != LUA_REFNIL)
{
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);
} }
}
/** Compute client geometry with respect to its geometry hints. /** Compute client geometry with respect to its geometry hints.
* \param c The client. * \param c The client.
@ -838,10 +848,14 @@ client_unmanage(client_t *c)
untag_client(c, tags->tab[i]); untag_client(c, tags->tab[i]);
/* call hook */ /* call hook */
if(globalconf.hooks.unmanage != LUA_REFNIL)
{
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 */ /* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0); luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
/* The server grab construct avoids race conditions. */ /* The server grab construct avoids race conditions. */
@ -1054,6 +1068,7 @@ luaA_client_swap(lua_State *L)
client_need_arrange(*swap); client_need_arrange(*swap);
/* Call hook to notify list change */ /* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(L, globalconf.hooks.clients, 0, 0); luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
return 0; return 0;

40
event.c
View File

@ -60,20 +60,32 @@ event_handle_mouse_button(client_t *c,
for(int i = 0; i < buttons->len; i++) for(int i = 0; i < buttons->len; i++)
if(button == buttons->tab[i]->button if(button == buttons->tab[i]->button
&& XUTIL_MASK_CLEAN(state) == buttons->tab[i]->mod) && XUTIL_MASK_CLEAN(state) == buttons->tab[i]->mod)
switch(type)
{
case XCB_BUTTON_PRESS:
if(buttons->tab[i]->press != LUA_REFNIL)
{ {
if(c) if(c)
{ {
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, luaA_dofunction(globalconf.L, buttons->tab[i]->press, 1, 0);
type == XCB_BUTTON_PRESS ?
buttons->tab[i]->press : buttons->tab[i]->release,
1, 0);
} }
else else
luaA_dofunction(globalconf.L, luaA_dofunction(globalconf.L, buttons->tab[i]->press, 0, 0);
type == XCB_BUTTON_PRESS ? }
buttons->tab[i]->press : buttons->tab[i]->release, break;
0, 0); case XCB_BUTTON_RELEASE:
if(buttons->tab[i]->release != LUA_REFNIL)
{
if(c)
{
luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, buttons->tab[i]->release, 1, 0);
}
else
luaA_dofunction(globalconf.L, buttons->tab[i]->release, 0, 0);
}
break;
} }
} }
@ -339,20 +351,26 @@ event_handle_widget_motionnotify(void *object,
if(w->widget != *mouse_over) if(w->widget != *mouse_over)
{ {
if(*mouse_over) if(*mouse_over)
{
if((*mouse_over)->mouse_leave != LUA_REFNIL)
{ {
/* call mouse leave function on old widget */ /* call mouse leave function on old widget */
luaA_wibox_userdata_new(globalconf.L, object); luaA_wibox_userdata_new(globalconf.L, object);
luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0); luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
} }
}
if(w) if(w)
{ {
/* call mouse enter function on new widget and register it */ /* call mouse enter function on new widget and register it */
*mouse_over = w->widget; *mouse_over = w->widget;
if(w->widget->mouse_enter != LUA_REFNIL)
{
luaA_wibox_userdata_new(globalconf.L, object); luaA_wibox_userdata_new(globalconf.L, object);
luaA_dofunction(globalconf.L, w->widget->mouse_enter, 1, 0); luaA_dofunction(globalconf.L, w->widget->mouse_enter, 1, 0);
} }
} }
} }
}
/** The motion notify event handler. /** The motion notify event handler.
* \param data currently unused. * \param data currently unused.
@ -394,10 +412,13 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
wibox_t *wibox = wibox_getbywin(ev->event); wibox_t *wibox = wibox_getbywin(ev->event);
if(wibox && wibox->mouse_over) if(wibox && wibox->mouse_over)
{
if(wibox->mouse_over->mouse_leave != LUA_REFNIL)
{ {
/* call mouse leave function on widget the mouse was over */ /* call mouse leave function on widget the mouse was over */
luaA_wibox_userdata_new(globalconf.L, wibox); luaA_wibox_userdata_new(globalconf.L, wibox);
luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0); luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
}
wibox->mouse_over = NULL; wibox->mouse_over = NULL;
} }
@ -445,9 +466,12 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
globalconf.pointer_x = ev->root_x; globalconf.pointer_x = ev->root_x;
globalconf.pointer_y = ev->root_y; globalconf.pointer_y = ev->root_y;
if(globalconf.hooks.mouse_enter != LUA_REFNIL)
{
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
} }
}
else if((emwin = xembed_getbywin(globalconf.embedded, ev->event))) else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
xutil_screen_get(connection, emwin->phys_screen)->root, xutil_screen_get(connection, emwin->phys_screen)->root,

4
ewmh.c
View File

@ -330,9 +330,7 @@ ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
c->isurgent = !c->isurgent; c->isurgent = !c->isurgent;
/* execute hook */ /* execute hook */
luaA_client_userdata_new(globalconf.L, c); hooks_property(c, "urgent");
lua_pushliteral(globalconf.L, "urgent");
luaA_dofunction(globalconf.L, globalconf.hooks.property, 2, 0);
} }
} }

View File

@ -72,9 +72,12 @@ arrange(int screen)
globalconf.screens[screen].need_arrange = false; globalconf.screens[screen].need_arrange = false;
/* call hook */ /* call hook */
if(globalconf.hooks.arrange != LUA_REFNIL)
{
lua_pushnumber(globalconf.L, screen + 1); lua_pushnumber(globalconf.L, screen + 1);
luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1, 0);
} }
}
/** Refresh the screen disposition /** Refresh the screen disposition
* \return true if the screen was arranged, false otherwise * \return true if the screen was arranged, false otherwise

1
luaa.c
View File

@ -1251,6 +1251,7 @@ luaA_cs_cleanup(void)
void void
luaA_on_timer(EV_P_ ev_timer *w, int revents) luaA_on_timer(EV_P_ ev_timer *w, int revents)
{ {
if(globalconf.hooks.timer != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0, 0); luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0, 0);
awesome_refresh(globalconf.connection); awesome_refresh(globalconf.connection);
} }

7
luaa.h
View File

@ -313,8 +313,6 @@ luaA_registerfct(lua_State *L, int idx, luaA_ref *fct)
*/ */
static inline bool static inline bool
luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret) luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret)
{
if(f != LUA_REFNIL)
{ {
lua_rawgeti(L, LUA_REGISTRYINDEX, f); lua_rawgeti(L, LUA_REGISTRYINDEX, f);
if(nargs) if(nargs)
@ -328,8 +326,6 @@ luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret)
} }
return true; return true;
} }
return false;
}
/** Print a warning about some Lua code. /** Print a warning about some Lua code.
* This is less mean than luaL_error() which setjmp via lua_error() and kills * This is less mean than luaL_error() which setjmp via lua_error() and kills
@ -378,9 +374,12 @@ bool luaA_isloop(lua_State *, int);
#define hooks_property(c, prop) \ #define hooks_property(c, prop) \
do { \ do { \
if(globalconf.hooks.property != LUA_REFNIL) \
{ \
luaA_client_userdata_new(globalconf.L, c); \ luaA_client_userdata_new(globalconf.L, c); \
lua_pushliteral(globalconf.L, prop); \ lua_pushliteral(globalconf.L, prop); \
luaA_dofunction(globalconf.L, globalconf.hooks.property, 2, 0); \ luaA_dofunction(globalconf.L, globalconf.hooks.property, 2, 0); \
} \
} while(0); } while(0);
#endif #endif

View File

@ -560,6 +560,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;
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0); luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
layout_refresh(); layout_refresh();
wibox_refresh(); wibox_refresh();

12
tag.c
View File

@ -100,9 +100,12 @@ tag_append_to_screen(tag_t *tag, screen_t *s)
client_saveprops_tags(c); client_saveprops_tags(c);
/* call hook */ /* call hook */
if(globalconf.hooks.tags != LUA_REFNIL)
{
lua_pushnumber(globalconf.L, s->index + 1); lua_pushnumber(globalconf.L, s->index + 1);
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.tags, 1, 0);
} }
}
/** Remove a tag from screen. Tag must be on a screen and have no clients. /** Remove a tag from screen. Tag must be on a screen and have no clients.
* \param tag The tag to remove. * \param tag The tag to remove.
@ -132,9 +135,12 @@ tag_remove_from_screen(tag_t *tag)
client_saveprops_tags(c); client_saveprops_tags(c);
/* call hook */ /* call hook */
if(globalconf.hooks.tags != LUA_REFNIL)
{
lua_pushnumber(globalconf.L, screen + 1); lua_pushnumber(globalconf.L, screen + 1);
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.tags, 1, 0);
} }
}
/** Tag a client with specified tag. /** Tag a client with specified tag.
* \param c the client to tag * \param c the client to tag
@ -152,10 +158,13 @@ tag_client(client_t *c, tag_t *t)
client_saveprops_tags(c); client_saveprops_tags(c);
client_need_arrange(c); client_need_arrange(c);
/* call hook */ /* call hook */
if(globalconf.hooks.tagged != LUA_REFNIL)
{
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_tag_userdata_new(globalconf.L, t); luaA_tag_userdata_new(globalconf.L, t);
luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0); luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0);
} }
}
/** Untag a client with specified tag. /** Untag a client with specified tag.
* \param c the client to tag * \param c the client to tag
@ -171,9 +180,12 @@ untag_client(client_t *c, tag_t *t)
client_array_take(&t->clients, i); client_array_take(&t->clients, i);
client_saveprops_tags(c); client_saveprops_tags(c);
/* call hook */ /* call hook */
if(globalconf.hooks.tagged != LUA_REFNIL)
{
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_tag_userdata_new(globalconf.L, t); luaA_tag_userdata_new(globalconf.L, t);
luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0); luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0);
}
tag_unref(&t); tag_unref(&t);
return; return;
} }

View File

@ -88,12 +88,22 @@ widget_common_button(widget_node_t *w,
for(int i = 0; i < b->len; i++) for(int i = 0; i < b->len; i++)
if(ev->detail == b->tab[i]->button if(ev->detail == b->tab[i]->button
&& XUTIL_MASK_CLEAN(ev->state) == b->tab[i]->mod) && XUTIL_MASK_CLEAN(ev->state) == b->tab[i]->mod)
switch(ev->response_type)
{
case XCB_BUTTON_PRESS:
if(b->tab[i]->press != LUA_REFNIL)
{ {
luaA_wibox_userdata_new(globalconf.L, p); luaA_wibox_userdata_new(globalconf.L, p);
luaA_dofunction(globalconf.L, luaA_dofunction(globalconf.L, b->tab[i]->press, 1, 0);
ev->response_type == XCB_BUTTON_PRESS ? }
b->tab[i]->press : b->tab[i]->release, break;
1, 0); case XCB_BUTTON_RELEASE:
if(b->tab[i]->release != LUA_REFNIL)
{
luaA_wibox_userdata_new(globalconf.L, p);
luaA_dofunction(globalconf.L, b->tab[i]->release, 1, 0);
}
break;
} }
} }