From a4224193d8e47a1f72b0f6f06d6553a21e9c754c Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 1 Oct 2008 17:45:07 +0200 Subject: [PATCH] widget: move widget_{set,get} Signed-off-by: Julien Danjou --- wibox.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ widget.c | 59 ------------------------------------------------------- widget.h | 2 -- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/wibox.c b/wibox.c index 2d9eaa690..7bb0507cd 100644 --- a/wibox.c +++ b/wibox.c @@ -728,6 +728,66 @@ luaA_wibox_index(lua_State *L) return 1; } +/** Generic widget set. + * \param L The Lua VM state. + * \param idx The table of widgets index. + * \param object The object the widget will be attached to. + * \param widgets The widgets to fill. + * \return The number of elements pushed on stack. + */ +static void +luaA_widget_set(lua_State *L, int idx, wibox_t *object, widget_node_t **widgets) +{ + widget_node_t *witer; + + luaA_checktable(L, idx); + + /* remove all widgets */ + for(witer = *widgets; witer; witer = *widgets) + { + if(witer->widget->detach) + witer->widget->detach(witer->widget, object); + widget_unref(&witer->widget); + widget_node_list_detach(widgets, witer); + p_delete(&witer); + } + + /* now read all widgets and add them */ + lua_pushnil(L); + while(lua_next(L, idx)) + { + widget_t **widget = luaA_checkudata(L, -1, "widget"); + widget_node_t *w = p_new(widget_node_t, 1); + w->widget = *widget; + widget_node_list_append(widgets, w); + widget_ref(widget); + lua_pop(L, 1); + } +} + +/** Generic widget get. + * \param L The Lua VM state. + * \param widget The widget list. + * \return The number of elements pushed on stack. + */ +static int +luaA_widget_get(lua_State *L, widget_node_t *widgets) +{ + widget_node_t *witer; + int i = 0; + + lua_newtable(L); + + for(witer = widgets; witer; witer = witer->next) + { + luaA_widget_userdata_new(L, witer->widget); + lua_rawseti(L, -2, ++i); + } + + return 1; +} + + /** Get or set the wibox widgets. * \param L The Lua VM state. * \return The number of elements pushed on stack. diff --git a/widget.c b/widget.c index d7b24af4a..a7b6428fa 100644 --- a/widget.c +++ b/widget.c @@ -404,65 +404,6 @@ luaA_widget_newindex(lua_State *L) return 0; } -/** Generic widget set. - * \param L The Lua VM state. - * \param idx The table of widgets index. - * \param object The object the widget will be attached to. - * \param widgets The widgets to fill. - * \return The number of elements pushed on stack. - */ -void -luaA_widget_set(lua_State *L, int idx, wibox_t *object, widget_node_t **widgets) -{ - widget_node_t *witer; - - luaA_checktable(L, idx); - - /* remove all widgets */ - for(witer = *widgets; witer; witer = *widgets) - { - if(witer->widget->detach) - witer->widget->detach(witer->widget, object); - widget_unref(&witer->widget); - widget_node_list_detach(widgets, witer); - p_delete(&witer); - } - - /* now read all widgets and add them */ - lua_pushnil(L); - while(lua_next(L, idx)) - { - widget_t **widget = luaA_checkudata(L, -1, "widget"); - widget_node_t *w = p_new(widget_node_t, 1); - w->widget = *widget; - widget_node_list_append(widgets, w); - widget_ref(widget); - lua_pop(L, 1); - } -} - -/** Generic widget get. - * \param L The Lua VM state. - * \param widget The widget list. - * \return The number of elements pushed on stack. - */ -int -luaA_widget_get(lua_State *L, widget_node_t *widgets) -{ - widget_node_t *witer; - int i = 0; - - lua_newtable(L); - - for(witer = widgets; witer; witer = witer->next) - { - luaA_widget_userdata_new(L, witer->widget); - lua_rawseti(L, -2, ++i); - } - - return 1; -} - const struct luaL_reg awesome_widget_methods[] = { { "__call", luaA_widget_new }, diff --git a/widget.h b/widget.h index 3d9b2ced2..320b7d82f 100644 --- a/widget.h +++ b/widget.h @@ -32,8 +32,6 @@ void widget_invalidate_cache(int, int); int widget_calculate_offset(int, int, int, int); void widget_common_new(widget_t *); void widget_render(widget_node_t *, draw_context_t *, xcb_gcontext_t, xcb_drawable_t, int, orientation_t, int, int, wibox_t *); -void luaA_widget_set(lua_State *, int, wibox_t *, widget_node_t **); -int luaA_widget_get(lua_State *, widget_node_t *); int luaA_widget_userdata_new(lua_State *, widget_t *);