screen: add signals support
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
fc035005ba
commit
7b04d8ef6f
79
screen.c
79
screen.c
|
@ -444,6 +444,82 @@ luaA_screen_index(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Add a signal to a screen.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
* \luastack
|
||||||
|
* \lvalue A screen.
|
||||||
|
* \lparam A signal name.
|
||||||
|
* \lparam A function to call when the signal is emited.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_screen_add_signal(lua_State *L)
|
||||||
|
{
|
||||||
|
screen_t *s = lua_touserdata(L, 1);
|
||||||
|
const char *name = luaL_checkstring(L, 2);
|
||||||
|
luaA_checkfunction(L, 3);
|
||||||
|
signal_add(&s->signals, name, luaA_object_ref(L, 3));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remove a signal to a screen.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
* \luastack
|
||||||
|
* \lvalue A screen.
|
||||||
|
* \lparam A signal name.
|
||||||
|
* \lparam A function to remove
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_screen_remove_signal(lua_State *L)
|
||||||
|
{
|
||||||
|
screen_t *s = lua_touserdata(L, 1);
|
||||||
|
const char *name = luaL_checkstring(L, 2);
|
||||||
|
luaA_checkfunction(L, 3);
|
||||||
|
const void *ref = lua_topointer(L, 3);
|
||||||
|
signal_remove(&s->signals, name, ref);
|
||||||
|
luaA_object_unref(L, (void *) ref);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Emit a signal to a screen.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \param screen The screen.
|
||||||
|
* \param name The signal name.
|
||||||
|
* \param nargs The number of arguments to the signal function.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
screen_emit_signal(lua_State *L, screen_t *screen, const char *name, int nargs)
|
||||||
|
{
|
||||||
|
signal_t *sigfound = signal_array_getbyid(&screen->signals,
|
||||||
|
a_strhash((const unsigned char *) name));
|
||||||
|
if(sigfound)
|
||||||
|
foreach(func, sigfound->sigfuncs)
|
||||||
|
{
|
||||||
|
luaA_pushscreen(L, screen);
|
||||||
|
for(int i = 0; i < nargs; i++)
|
||||||
|
lua_pushvalue(L, - nargs - 1);
|
||||||
|
luaA_object_push(L, (void *) *func);
|
||||||
|
luaA_dofunction(L, nargs + 1, 0);
|
||||||
|
}
|
||||||
|
lua_pop(L, nargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Emit a signal to a screen.
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
* \luastack
|
||||||
|
* \lvalue A screen.
|
||||||
|
* \lparam A signal name.
|
||||||
|
* \lparam Various arguments, optional.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
luaA_screen_emit_signal(lua_State *L)
|
||||||
|
{
|
||||||
|
screen_emit_signal(L, lua_touserdata(L, 1), luaL_checkstring(L, 2), lua_gettop(L) - 2);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Get the screen count.
|
/** Get the screen count.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
|
@ -467,6 +543,9 @@ const struct luaL_reg awesome_screen_methods[] =
|
||||||
|
|
||||||
const struct luaL_reg awesome_screen_meta[] =
|
const struct luaL_reg awesome_screen_meta[] =
|
||||||
{
|
{
|
||||||
|
{ "add_signal", luaA_screen_add_signal },
|
||||||
|
{ "remove_signal", luaA_screen_remove_signal },
|
||||||
|
{ "emit_signal", luaA_screen_emit_signal },
|
||||||
{ "tags", luaA_screen_tags },
|
{ "tags", luaA_screen_tags },
|
||||||
{ "__index", luaA_screen_index },
|
{ "__index", luaA_screen_index },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
|
|
3
screen.h
3
screen.h
|
@ -47,9 +47,12 @@ struct a_screen
|
||||||
SnMonitorContext *snmonitor;
|
SnMonitorContext *snmonitor;
|
||||||
/** The default visual, used to draw */
|
/** The default visual, used to draw */
|
||||||
xcb_visualtype_t *visual;
|
xcb_visualtype_t *visual;
|
||||||
|
/** The signals emited by screen objects */
|
||||||
|
signal_array_t signals;
|
||||||
};
|
};
|
||||||
ARRAY_FUNCS(screen_t, screen, DO_NOTHING)
|
ARRAY_FUNCS(screen_t, screen, DO_NOTHING)
|
||||||
|
|
||||||
|
void screen_emit_signal(lua_State *, screen_t *, const char *, int);
|
||||||
void screen_scan(void);
|
void screen_scan(void);
|
||||||
screen_t *screen_getbycoord(screen_t *, int, int);
|
screen_t *screen_getbycoord(screen_t *, int, int);
|
||||||
area_t screen_area_get(screen_t *, bool);
|
area_t screen_area_get(screen_t *, bool);
|
||||||
|
|
Loading…
Reference in New Issue