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:
parent
ee8bcd6c43
commit
d1db6903fa
15
client.c
15
client.c
|
@ -161,8 +161,11 @@ client_unfocus(client_t *c)
|
|||
globalconf.screens[c->phys_screen].client_focus = NULL;
|
||||
|
||||
/* Call hook */
|
||||
if(globalconf.hooks.unfocus != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
|
||||
}
|
||||
|
||||
ewmh_update_net_active_window(c->phys_screen);
|
||||
}
|
||||
|
@ -217,8 +220,11 @@ client_focus(client_t *c)
|
|||
client_need_arrange(c);
|
||||
|
||||
/* execute hook */
|
||||
if(globalconf.hooks.focus != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* Call hook to notify list change */
|
||||
if(globalconf.hooks.clients != LUA_REFNIL)
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
|
||||
|
||||
/* call hook */
|
||||
if(globalconf.hooks.manage != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute client geometry with respect to its geometry hints.
|
||||
* \param c The client.
|
||||
|
@ -838,10 +848,14 @@ client_unmanage(client_t *c)
|
|||
untag_client(c, tags->tab[i]);
|
||||
|
||||
/* call hook */
|
||||
if(globalconf.hooks.unmanage != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
|
||||
}
|
||||
|
||||
/* Call hook to notify list change */
|
||||
if(globalconf.hooks.clients != LUA_REFNIL)
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
|
||||
|
||||
/* The server grab construct avoids race conditions. */
|
||||
|
@ -1054,6 +1068,7 @@ luaA_client_swap(lua_State *L)
|
|||
client_need_arrange(*swap);
|
||||
|
||||
/* Call hook to notify list change */
|
||||
if(globalconf.hooks.clients != LUA_REFNIL)
|
||||
luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
|
||||
|
||||
return 0;
|
||||
|
|
40
event.c
40
event.c
|
@ -60,20 +60,32 @@ event_handle_mouse_button(client_t *c,
|
|||
for(int i = 0; i < buttons->len; i++)
|
||||
if(button == buttons->tab[i]->button
|
||||
&& XUTIL_MASK_CLEAN(state) == buttons->tab[i]->mod)
|
||||
switch(type)
|
||||
{
|
||||
case XCB_BUTTON_PRESS:
|
||||
if(buttons->tab[i]->press != LUA_REFNIL)
|
||||
{
|
||||
if(c)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_dofunction(globalconf.L,
|
||||
type == XCB_BUTTON_PRESS ?
|
||||
buttons->tab[i]->press : buttons->tab[i]->release,
|
||||
1, 0);
|
||||
luaA_dofunction(globalconf.L, buttons->tab[i]->press, 1, 0);
|
||||
}
|
||||
else
|
||||
luaA_dofunction(globalconf.L,
|
||||
type == XCB_BUTTON_PRESS ?
|
||||
buttons->tab[i]->press : buttons->tab[i]->release,
|
||||
0, 0);
|
||||
luaA_dofunction(globalconf.L, buttons->tab[i]->press, 0, 0);
|
||||
}
|
||||
break;
|
||||
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(*mouse_over)
|
||||
{
|
||||
if((*mouse_over)->mouse_leave != LUA_REFNIL)
|
||||
{
|
||||
/* call mouse leave function on old widget */
|
||||
luaA_wibox_userdata_new(globalconf.L, object);
|
||||
luaA_dofunction(globalconf.L, (*mouse_over)->mouse_leave, 1, 0);
|
||||
}
|
||||
}
|
||||
if(w)
|
||||
{
|
||||
/* call mouse enter function on new widget and register it */
|
||||
*mouse_over = w->widget;
|
||||
if(w->widget->mouse_enter != LUA_REFNIL)
|
||||
{
|
||||
luaA_wibox_userdata_new(globalconf.L, object);
|
||||
luaA_dofunction(globalconf.L, w->widget->mouse_enter, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The motion notify event handler.
|
||||
* \param data currently unused.
|
||||
|
@ -394,10 +412,13 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
|
|||
wibox_t *wibox = wibox_getbywin(ev->event);
|
||||
|
||||
if(wibox && wibox->mouse_over)
|
||||
{
|
||||
if(wibox->mouse_over->mouse_leave != LUA_REFNIL)
|
||||
{
|
||||
/* call mouse leave function on widget the mouse was over */
|
||||
luaA_wibox_userdata_new(globalconf.L, wibox);
|
||||
luaA_dofunction(globalconf.L, wibox->mouse_over->mouse_leave, 1, 0);
|
||||
}
|
||||
wibox->mouse_over = NULL;
|
||||
}
|
||||
|
||||
|
@ -445,9 +466,12 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
|
|||
globalconf.pointer_x = ev->root_x;
|
||||
globalconf.pointer_y = ev->root_y;
|
||||
|
||||
if(globalconf.hooks.mouse_enter != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.mouse_enter, 1, 0);
|
||||
}
|
||||
}
|
||||
else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
|
||||
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
|
||||
xutil_screen_get(connection, emwin->phys_screen)->root,
|
||||
|
|
4
ewmh.c
4
ewmh.c
|
@ -330,9 +330,7 @@ ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
|
|||
c->isurgent = !c->isurgent;
|
||||
|
||||
/* execute hook */
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
lua_pushliteral(globalconf.L, "urgent");
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.property, 2, 0);
|
||||
hooks_property(c, "urgent");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
layout.c
3
layout.c
|
@ -72,9 +72,12 @@ arrange(int screen)
|
|||
globalconf.screens[screen].need_arrange = false;
|
||||
|
||||
/* call hook */
|
||||
if(globalconf.hooks.arrange != LUA_REFNIL)
|
||||
{
|
||||
lua_pushnumber(globalconf.L, screen + 1);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Refresh the screen disposition
|
||||
* \return true if the screen was arranged, false otherwise
|
||||
|
|
1
luaa.c
1
luaa.c
|
@ -1251,6 +1251,7 @@ luaA_cs_cleanup(void)
|
|||
void
|
||||
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);
|
||||
awesome_refresh(globalconf.connection);
|
||||
}
|
||||
|
|
7
luaa.h
7
luaa.h
|
@ -313,8 +313,6 @@ luaA_registerfct(lua_State *L, int idx, luaA_ref *fct)
|
|||
*/
|
||||
static inline bool
|
||||
luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret)
|
||||
{
|
||||
if(f != LUA_REFNIL)
|
||||
{
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, f);
|
||||
if(nargs)
|
||||
|
@ -328,8 +326,6 @@ luaA_dofunction(lua_State *L, luaA_ref f, int nargs, int nret)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Print a warning about some Lua code.
|
||||
* 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) \
|
||||
do { \
|
||||
if(globalconf.hooks.property != LUA_REFNIL) \
|
||||
{ \
|
||||
luaA_client_userdata_new(globalconf.L, c); \
|
||||
lua_pushliteral(globalconf.L, prop); \
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.property, 2, 0); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#endif
|
||||
|
|
1
mouse.c
1
mouse.c
|
@ -560,6 +560,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;
|
||||
if(globalconf.hooks.clients != LUA_REFNIL)
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
|
||||
layout_refresh();
|
||||
wibox_refresh();
|
||||
|
|
12
tag.c
12
tag.c
|
@ -100,9 +100,12 @@ tag_append_to_screen(tag_t *tag, screen_t *s)
|
|||
client_saveprops_tags(c);
|
||||
|
||||
/* call hook */
|
||||
if(globalconf.hooks.tags != LUA_REFNIL)
|
||||
{
|
||||
lua_pushnumber(globalconf.L, s->index + 1);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove a tag from screen. Tag must be on a screen and have no clients.
|
||||
* \param tag The tag to remove.
|
||||
|
@ -132,9 +135,12 @@ tag_remove_from_screen(tag_t *tag)
|
|||
client_saveprops_tags(c);
|
||||
|
||||
/* call hook */
|
||||
if(globalconf.hooks.tags != LUA_REFNIL)
|
||||
{
|
||||
lua_pushnumber(globalconf.L, screen + 1);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.tags, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Tag a client with specified tag.
|
||||
* \param c the client to tag
|
||||
|
@ -152,10 +158,13 @@ tag_client(client_t *c, tag_t *t)
|
|||
client_saveprops_tags(c);
|
||||
client_need_arrange(c);
|
||||
/* call hook */
|
||||
if(globalconf.hooks.tagged != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_tag_userdata_new(globalconf.L, t);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Untag a client with specified 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_saveprops_tags(c);
|
||||
/* call hook */
|
||||
if(globalconf.hooks.tagged != LUA_REFNIL)
|
||||
{
|
||||
luaA_client_userdata_new(globalconf.L, c);
|
||||
luaA_tag_userdata_new(globalconf.L, t);
|
||||
luaA_dofunction(globalconf.L, globalconf.hooks.tagged, 2, 0);
|
||||
}
|
||||
tag_unref(&t);
|
||||
return;
|
||||
}
|
||||
|
|
18
widget.c
18
widget.c
|
@ -88,12 +88,22 @@ widget_common_button(widget_node_t *w,
|
|||
for(int i = 0; i < b->len; i++)
|
||||
if(ev->detail == b->tab[i]->button
|
||||
&& 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_dofunction(globalconf.L,
|
||||
ev->response_type == XCB_BUTTON_PRESS ?
|
||||
b->tab[i]->press : b->tab[i]->release,
|
||||
1, 0);
|
||||
luaA_dofunction(globalconf.L, b->tab[i]->press, 1, 0);
|
||||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue