lua{class,object}: {add,remove}_signal() take lua_CFunction as arg
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
c8dea3cff6
commit
f523b37e1d
|
@ -248,7 +248,14 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
luaA_checkfunction(L, ud);
|
||||
|
@ -256,7 +263,7 @@ luaA_class_add_signal(lua_State *L, lua_class_t *lua_class,
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
luaA_checkfunction(L, ud);
|
||||
|
|
|
@ -73,8 +73,9 @@ struct lua_class_t
|
|||
const char * luaA_typename(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_remove_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_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_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 \
|
||||
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; \
|
||||
} \
|
||||
\
|
||||
static inline int \
|
||||
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); \
|
||||
return 0; \
|
||||
} \
|
||||
|
|
|
@ -148,6 +148,22 @@ luaA_settype(lua_State *L, lua_class_t *lua_class)
|
|||
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.
|
||||
* \param L The Lua VM state.
|
||||
* \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.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
luaA_checkfunction(L, ud);
|
||||
|
@ -260,14 +276,14 @@ luaA_object_emit_signal(lua_State *L, int oud,
|
|||
int
|
||||
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;
|
||||
}
|
||||
|
||||
int
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 luaA_object_add_signal(lua_State *, int, const char *, int);
|
||||
void luaA_object_remove_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 *, 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);
|
||||
|
||||
int luaA_object_add_signal_simple(lua_State *);
|
||||
|
|
39
ewmh.c
39
ewmh.c
|
@ -80,20 +80,16 @@ ewmh_client_update_hints(lua_State *L)
|
|||
static int
|
||||
ewmh_signal_on_client_new(lua_State *L)
|
||||
{
|
||||
#define DO_ADD_SIGNAL_FOR_PROPERTY(prop) \
|
||||
lua_pushcfunction(L, ewmh_client_update_hints); \
|
||||
luaA_object_add_signal(L, 1, "property::" #prop , -1);
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(modal)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(fullscreen)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(maximized_horizontal)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(maximized_vertical)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(sticky)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(skip_taskbar)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(above)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(below)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(minimized)
|
||||
DO_ADD_SIGNAL_FOR_PROPERTY(urgent)
|
||||
#undef DO_ADD_SIGNAL_FOR_PROPERTY
|
||||
luaA_object_add_signal(L, 1, "property::modal" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::fullscreen" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::maximized_horizontal" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::maximized_vertical" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::sticky" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::skip_taskbar" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::above" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::below" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::minimized" , ewmh_client_update_hints);
|
||||
luaA_object_add_signal(L, 1, "property::urgent" , ewmh_client_update_hints);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -226,16 +222,11 @@ ewmh_init(void)
|
|||
|
||||
ewmh_update_desktop_geometry();
|
||||
|
||||
lua_pushcfunction(globalconf.L, ewmh_signal_on_client_new);
|
||||
luaA_class_add_signal(globalconf.L, &client_class, "new", -1);
|
||||
lua_pushcfunction(globalconf.L, ewmh_update_net_active_window);
|
||||
luaA_class_add_signal(globalconf.L, &client_class, "focus", -1);
|
||||
lua_pushcfunction(globalconf.L, ewmh_update_net_active_window);
|
||||
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);
|
||||
luaA_class_add_signal(globalconf.L, &client_class, "new", ewmh_signal_on_client_new);
|
||||
luaA_class_add_signal(globalconf.L, &client_class, "focus", 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, "manage", ewmh_update_net_client_list);
|
||||
luaA_class_add_signal(globalconf.L, &client_class, "unmanage", ewmh_update_net_client_list);
|
||||
}
|
||||
|
||||
/** Set the client list in stacking order, bottom to top.
|
||||
|
|
|
@ -770,8 +770,7 @@ luaA_wibox_new(lua_State *L)
|
|||
if(!w->geometry.height)
|
||||
w->geometry.height = 1;
|
||||
|
||||
lua_pushcfunction(L, luaA_wibox_need_update);
|
||||
luaA_object_add_signal(L, -2, "property::border_width", -1);
|
||||
luaA_object_add_signal(L, -2, "property::border_width", luaA_wibox_need_update);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue