[titlebar] Add titlebar_widget_get()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-04 13:29:45 +02:00
parent 131f31c561
commit 70dbc724bf
2 changed files with 25 additions and 1 deletions

View File

@ -479,7 +479,7 @@ luaA_statusbar_new(lua_State *L)
static int static int
luaA_statusbar_widget_get(lua_State *L) luaA_statusbar_widget_get(lua_State *L)
{ {
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar");; statusbar_t **sb = luaL_checkudata(L, 1, "statusbar");
widget_node_t *widget; widget_node_t *widget;
int i = 1; int i = 1;

View File

@ -455,6 +455,29 @@ luaA_titlebar_widget_add(lua_State *L)
return 0; return 0;
} }
/** Get all widgets from a titlebar.
* \return A table with all widgets from the titlebar.
*/
static int
luaA_titlebar_widget_get(lua_State *L)
{
titlebar_t **tb = luaL_checkudata(L, 1, "titlebar");
widget_node_t *widget;
int i = 1;
lua_newtable(L);
for(widget = (*tb)->widgets; widget; widget = widget->next)
{
luaA_widget_userdata_new(widget->widget);
/* ref again for the list */
widget_ref(&widget->widget);
lua_rawseti(L, -2, i++);
}
return 1;
}
static int static int
luaA_titlebar_gc(lua_State *L) luaA_titlebar_gc(lua_State *L)
{ {
@ -488,6 +511,7 @@ const struct luaL_reg awesome_titlebar_methods[] =
const struct luaL_reg awesome_titlebar_meta[] = const struct luaL_reg awesome_titlebar_meta[] =
{ {
{ "widget_add", luaA_titlebar_widget_add }, { "widget_add", luaA_titlebar_widget_add },
{ "widget_get", luaA_titlebar_widget_get },
{ "__eq", luaA_titlebar_eq }, { "__eq", luaA_titlebar_eq },
{ "__gc", luaA_titlebar_gc }, { "__gc", luaA_titlebar_gc },
{ "__tostring", luaA_titlebar_tostring }, { "__tostring", luaA_titlebar_tostring },