From 70dbc724bf3d6e0dab35d601c1da754c6166f880 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 4 Jun 2008 13:29:45 +0200 Subject: [PATCH] [titlebar] Add titlebar_widget_get() Signed-off-by: Julien Danjou --- statusbar.c | 2 +- titlebar.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/statusbar.c b/statusbar.c index 2593d485..46c6181d 100644 --- a/statusbar.c +++ b/statusbar.c @@ -479,7 +479,7 @@ luaA_statusbar_new(lua_State *L) static int 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; int i = 1; diff --git a/titlebar.c b/titlebar.c index d9ecf645..075a3617 100644 --- a/titlebar.c +++ b/titlebar.c @@ -455,6 +455,29 @@ luaA_titlebar_widget_add(lua_State *L) 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 luaA_titlebar_gc(lua_State *L) { @@ -488,6 +511,7 @@ const struct luaL_reg awesome_titlebar_methods[] = const struct luaL_reg awesome_titlebar_meta[] = { { "widget_add", luaA_titlebar_widget_add }, + { "widget_get", luaA_titlebar_widget_get }, { "__eq", luaA_titlebar_eq }, { "__gc", luaA_titlebar_gc }, { "__tostring", luaA_titlebar_tostring },