widget: move widget_{set,get}

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-01 17:45:07 +02:00
parent 683b1a9572
commit a4224193d8
3 changed files with 60 additions and 61 deletions

60
wibox.c
View File

@ -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.

View File

@ -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 },

View File

@ -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 *);