From 35b5afe38c493aa965416a88be84fd760eaafeca Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 4 Jun 2008 13:25:34 +0200 Subject: [PATCH] [widget] Move widget_get to statusbar Signed-off-by: Julien Danjou --- statusbar.c | 24 ++++++++++++++++++++++++ widget.c | 44 +------------------------------------------- widget.h | 2 ++ 3 files changed, 27 insertions(+), 43 deletions(-) diff --git a/statusbar.c b/statusbar.c index 75ad2c79..2593d485 100644 --- a/statusbar.c +++ b/statusbar.c @@ -473,6 +473,29 @@ luaA_statusbar_new(lua_State *L) return luaA_settype(L, "statusbar"); } +/** Get all widget from a statusbar. + * \return A table with all widgets from the statusbar. + */ +static int +luaA_statusbar_widget_get(lua_State *L) +{ + statusbar_t **sb = luaL_checkudata(L, 1, "statusbar");; + widget_node_t *widget; + int i = 1; + + lua_newtable(L); + + for(widget = (*sb)->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; +} + /** Handle statusbar garbage collection. */ static int @@ -491,6 +514,7 @@ const struct luaL_reg awesome_statusbar_methods[] = const struct luaL_reg awesome_statusbar_meta[] = { { "widget_add", luaA_statusbar_widget_add }, + { "widget_get", luaA_statusbar_widget_get }, { "position_set", luaA_statusbar_position_set }, { "position_get", luaA_statusbar_position_get }, { "align_set", luaA_statusbar_align_set }, diff --git a/widget.c b/widget.c index 579b4fd1..80362874 100644 --- a/widget.c +++ b/widget.c @@ -296,7 +296,7 @@ widget_invalidate_bywidget(widget_t *widget) * \param widget The widget. * \return Return luaA_settype() return value. */ -static int +int luaA_widget_userdata_new(widget_t *widget) { widget_t **w; @@ -464,47 +464,6 @@ luaA_widget_eq(lua_State *L) return 1; } -/** Get all widget from all statusbars. - * \return A table with all widgets from all statusbars. - */ -static int -luaA_widget_get(lua_State *L) -{ - statusbar_t *sb; - widget_node_t *widget; - int i = 1, screen; - bool add = true; - widget_node_t *wlist = NULL, *witer; - - lua_newtable(L); - - for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) - for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next) - for(widget = sb->widgets; widget; widget = widget->next) - { - for(witer = wlist; witer; witer = witer->next) - if(witer->widget == widget->widget) - { - add = false; - break; - } - if(add) - { - witer = p_new(widget_node_t, 1); - widget_node_list_push(&wlist, witer); - luaA_widget_userdata_new(witer->widget); - /* ref again for the list */ - widget_ref(&widget->widget); - lua_rawseti(L, -2, i++); - } - add = true; - } - - widget_node_list_wipe(&wlist); - - return 1; -} - /** Set the widget name. * \param A string with the new widget name. */ @@ -556,7 +515,6 @@ luaA_widget_visible_get(lua_State *L) const struct luaL_reg awesome_widget_methods[] = { { "new", luaA_widget_new }, - { "get", luaA_widget_get }, { NULL, NULL } }; const struct luaL_reg awesome_widget_meta[] = diff --git a/widget.h b/widget.h index 8d071101..c4746892 100644 --- a/widget.h +++ b/widget.h @@ -39,6 +39,8 @@ widget_t * widget_getbyname(const char *); void widget_tell_managestatus(widget_t *, widget_tell_status_t, const char *); void widget_render(widget_node_t *, draw_context_t *, xcb_gcontext_t, xcb_drawable_t, int, position_t, int, int, void *); +int luaA_widget_userdata_new(widget_t *); + widget_constructor_t taglist_new; widget_constructor_t textbox_new; widget_constructor_t iconbox_new;