lua{class,object}: {add,remove}_signal() take lua_CFunction as arg

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-10-09 20:32:33 +02:00 committed by Uli Schlachter
parent c8dea3cff6
commit f523b37e1d
6 changed files with 60 additions and 43 deletions

View File

@ -248,7 +248,14 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
} }
void void
luaA_class_add_signal(lua_State *L, lua_class_t *lua_class, luaA_class_add_signal(lua_State *L, lua_class_t *lua_class, const char *name, lua_CFunction fn)
{
lua_pushcfunction(L, fn);
luaA_class_add_signal_from_stack(L, lua_class, name, -1);
}
void
luaA_class_add_signal_from_stack(lua_State *L, lua_class_t *lua_class,
const char *name, int ud) const char *name, int ud)
{ {
luaA_checkfunction(L, ud); luaA_checkfunction(L, ud);
@ -256,7 +263,7 @@ luaA_class_add_signal(lua_State *L, lua_class_t *lua_class,
} }
void void
luaA_class_remove_signal(lua_State *L, lua_class_t *lua_class, luaA_class_remove_signal_from_stack(lua_State *L, lua_class_t *lua_class,
const char *name, int ud) const char *name, int ud)
{ {
luaA_checkfunction(L, ud); luaA_checkfunction(L, ud);

View File

@ -73,8 +73,9 @@ struct lua_class_t
const char * luaA_typename(lua_State *, int); const char * luaA_typename(lua_State *, int);
lua_class_t * luaA_class_get(lua_State *, int); lua_class_t * luaA_class_get(lua_State *, int);
void luaA_class_add_signal(lua_State *, lua_class_t *, const char *, int); void luaA_class_add_signal(lua_State *, lua_class_t *, const char *, lua_CFunction);
void luaA_class_remove_signal(lua_State *, lua_class_t *, const char *, int); void luaA_class_add_signal_from_stack(lua_State *, lua_class_t *, const char *, int);
void luaA_class_remove_signal_from_stack(lua_State *, lua_class_t *, const char *, int);
void luaA_class_emit_signal(lua_State *, lua_class_t *, const char *, int); void luaA_class_emit_signal(lua_State *, lua_class_t *, const char *, int);
void luaA_openlib(lua_State *, const char *, const struct luaL_reg[], const struct luaL_reg[]); void luaA_openlib(lua_State *, const char *, const struct luaL_reg[], const struct luaL_reg[]);
@ -107,14 +108,15 @@ luaA_checkudataornil(lua_State *L, int udx, lua_class_t *class)
static inline int \ static inline int \
luaA_##prefix##_class_add_signal(lua_State *L) \ luaA_##prefix##_class_add_signal(lua_State *L) \
{ \ { \
luaA_class_add_signal(L, &(lua_class), luaL_checkstring(L, 1), 2); \ luaA_class_add_signal_from_stack(L, &(lua_class), \
luaL_checkstring(L, 1), 2); \
return 0; \ return 0; \
} \ } \
\ \
static inline int \ static inline int \
luaA_##prefix##_class_remove_signal(lua_State *L) \ luaA_##prefix##_class_remove_signal(lua_State *L) \
{ \ { \
luaA_class_remove_signal(L, &(lua_class), \ luaA_class_remove_signal_from_stack(L, &(lua_class), \
luaL_checkstring(L, 1), 2); \ luaL_checkstring(L, 1), 2); \
return 0; \ return 0; \
} \ } \

View File

@ -148,6 +148,22 @@ luaA_settype(lua_State *L, lua_class_t *lua_class)
return 1; return 1;
} }
void
luaA_object_add_signal(lua_State *L, int oud,
const char *name, lua_CFunction fn)
{
lua_pushcfunction(L, fn);
luaA_object_add_signal_from_stack(L, oud, name, -1);
}
void
luaA_object_remove_signal(lua_State *L, int oud,
const char *name, lua_CFunction fn)
{
lua_pushcfunction(L, fn);
luaA_object_remove_signal_from_stack(L, oud, name, -1);
}
/** Add a signal to an object. /** Add a signal to an object.
* \param L The Lua VM state. * \param L The Lua VM state.
* \param oud The object index on the stack. * \param oud The object index on the stack.
@ -155,7 +171,7 @@ luaA_settype(lua_State *L, lua_class_t *lua_class)
* \param ud The index of function to call when signal is emitted. * \param ud The index of function to call when signal is emitted.
*/ */
void void
luaA_object_add_signal(lua_State *L, int oud, luaA_object_add_signal_from_stack(lua_State *L, int oud,
const char *name, int ud) const char *name, int ud)
{ {
luaA_checkfunction(L, ud); luaA_checkfunction(L, ud);
@ -170,7 +186,7 @@ luaA_object_add_signal(lua_State *L, int oud,
* \param ud The index of function to call when signal is emitted. * \param ud The index of function to call when signal is emitted.
*/ */
void void
luaA_object_remove_signal(lua_State *L, int oud, luaA_object_remove_signal_from_stack(lua_State *L, int oud,
const char *name, int ud) const char *name, int ud)
{ {
luaA_checkfunction(L, ud); luaA_checkfunction(L, ud);
@ -260,14 +276,14 @@ luaA_object_emit_signal(lua_State *L, int oud,
int int
luaA_object_add_signal_simple(lua_State *L) luaA_object_add_signal_simple(lua_State *L)
{ {
luaA_object_add_signal(L, 1, luaL_checkstring(L, 2), 3); luaA_object_add_signal_from_stack(L, 1, luaL_checkstring(L, 2), 3);
return 0; return 0;
} }
int int
luaA_object_remove_signal_simple(lua_State *L) luaA_object_remove_signal_simple(lua_State *L)
{ {
luaA_object_remove_signal(L, 1, luaL_checkstring(L, 2), 3); luaA_object_remove_signal_from_stack(L, 1, luaL_checkstring(L, 2), 3);
return 0; return 0;
} }

View File

@ -150,8 +150,10 @@ luaA_object_push(lua_State *L, void *pointer)
void signal_object_emit(lua_State *, signal_array_t *, const char *, int); void signal_object_emit(lua_State *, signal_array_t *, const char *, int);
void luaA_object_add_signal(lua_State *, int, const char *, int); void luaA_object_add_signal(lua_State *, int, const char *, lua_CFunction);
void luaA_object_remove_signal(lua_State *, int, const char *, int); void luaA_object_remove_signal(lua_State *, int, const char *, lua_CFunction);
void luaA_object_add_signal_from_stack(lua_State *, int, const char *, int);
void luaA_object_remove_signal_from_stack(lua_State *, int, const char *, int);
void luaA_object_emit_signal(lua_State *, int, const char *, int); void luaA_object_emit_signal(lua_State *, int, const char *, int);
int luaA_object_add_signal_simple(lua_State *); int luaA_object_add_signal_simple(lua_State *);

39
ewmh.c
View File

@ -80,20 +80,16 @@ ewmh_client_update_hints(lua_State *L)
static int static int
ewmh_signal_on_client_new(lua_State *L) ewmh_signal_on_client_new(lua_State *L)
{ {
#define DO_ADD_SIGNAL_FOR_PROPERTY(prop) \ luaA_object_add_signal(L, 1, "property::modal" , ewmh_client_update_hints);
lua_pushcfunction(L, ewmh_client_update_hints); \ luaA_object_add_signal(L, 1, "property::fullscreen" , ewmh_client_update_hints);
luaA_object_add_signal(L, 1, "property::" #prop , -1); luaA_object_add_signal(L, 1, "property::maximized_horizontal" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(modal) luaA_object_add_signal(L, 1, "property::maximized_vertical" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(fullscreen) luaA_object_add_signal(L, 1, "property::sticky" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(maximized_horizontal) luaA_object_add_signal(L, 1, "property::skip_taskbar" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(maximized_vertical) luaA_object_add_signal(L, 1, "property::above" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(sticky) luaA_object_add_signal(L, 1, "property::below" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(skip_taskbar) luaA_object_add_signal(L, 1, "property::minimized" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(above) luaA_object_add_signal(L, 1, "property::urgent" , ewmh_client_update_hints);
DO_ADD_SIGNAL_FOR_PROPERTY(below)
DO_ADD_SIGNAL_FOR_PROPERTY(minimized)
DO_ADD_SIGNAL_FOR_PROPERTY(urgent)
#undef DO_ADD_SIGNAL_FOR_PROPERTY
return 0; return 0;
} }
@ -226,16 +222,11 @@ ewmh_init(void)
ewmh_update_desktop_geometry(); ewmh_update_desktop_geometry();
lua_pushcfunction(globalconf.L, ewmh_signal_on_client_new); luaA_class_add_signal(globalconf.L, &client_class, "new", ewmh_signal_on_client_new);
luaA_class_add_signal(globalconf.L, &client_class, "new", -1); luaA_class_add_signal(globalconf.L, &client_class, "focus", ewmh_update_net_active_window);
lua_pushcfunction(globalconf.L, ewmh_update_net_active_window); luaA_class_add_signal(globalconf.L, &client_class, "unfocus", ewmh_update_net_active_window);
luaA_class_add_signal(globalconf.L, &client_class, "focus", -1); luaA_class_add_signal(globalconf.L, &client_class, "manage", ewmh_update_net_client_list);
lua_pushcfunction(globalconf.L, ewmh_update_net_active_window); luaA_class_add_signal(globalconf.L, &client_class, "unmanage", ewmh_update_net_client_list);
luaA_class_add_signal(globalconf.L, &client_class, "unfocus", -1);
lua_pushcfunction(globalconf.L, ewmh_update_net_client_list);
luaA_class_add_signal(globalconf.L, &client_class, "manage", -1);
lua_pushcfunction(globalconf.L, ewmh_update_net_client_list);
luaA_class_add_signal(globalconf.L, &client_class, "unmanage", -1);
} }
/** Set the client list in stacking order, bottom to top. /** Set the client list in stacking order, bottom to top.

View File

@ -770,8 +770,7 @@ luaA_wibox_new(lua_State *L)
if(!w->geometry.height) if(!w->geometry.height)
w->geometry.height = 1; w->geometry.height = 1;
lua_pushcfunction(L, luaA_wibox_need_update); luaA_object_add_signal(L, -2, "property::border_width", luaA_wibox_need_update);
luaA_object_add_signal(L, -2, "property::border_width", -1);
return 1; return 1;
} }