[widget] Add a visible attribute to widgets and Lua functions

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-23 19:29:55 +02:00
parent f76357499c
commit ffdb9727b7
3 changed files with 26 additions and 3 deletions

View File

@ -50,16 +50,16 @@ statusbar_draw(statusbar_t *statusbar)
statusbar->colors.bg);
for(w = statusbar->widgets; w; w = w->next)
if(w->widget->align == AlignLeft)
if(w->widget->isvisible && w->widget->align == AlignLeft)
left += w->widget->draw(w, statusbar, left, (left + right));
/* renders right widget from last to first */
for(w = *widget_node_list_last(&statusbar->widgets); w; w = w->prev)
if(w->widget->align == AlignRight)
if(w->widget->isvisible && w->widget->align == AlignRight)
right += w->widget->draw(w, statusbar, right, (left + right));
for(w = statusbar->widgets; w; w = w->next)
if(w->widget->align == AlignFlex)
if(w->widget->isvisible && w->widget->align == AlignFlex)
left += w->widget->draw(w, statusbar, left, (left + right));
switch(statusbar->position)

View File

@ -145,6 +145,8 @@ struct widget_t
button_t *buttons;
/** Cache flags */
int cache_flags;
/** True if the widget is visible */
bool isvisible;
};
struct widget_node_t

View File

@ -176,6 +176,8 @@ luaA_widget_new(lua_State *L)
widget = lua_newuserdata(L, sizeof(widget_t *));
objpos = lua_gettop(L);
*widget = w;
/* Set visible by default. */
w->isvisible = true;
/* \todo check that the name is unique */
(*widget)->name = luaA_name_init(L);
@ -352,6 +354,23 @@ luaA_widget_name_get(lua_State *L)
return 1;
}
static int
luaA_widget_visible_set(lua_State *L)
{
widget_t **widget = luaL_checkudata(L, 1, "widget");
(*widget)->isvisible = luaA_checkboolean(L, 2);
widget_invalidate_statusbar_bywidget(*widget);
return 0;
}
static int
luaA_widget_visible_get(lua_State *L)
{
widget_t **widget = luaL_checkudata(L, 1, "widget");
lua_pushboolean(L, (*widget)->isvisible);
return 1;
}
const struct luaL_reg awesome_widget_methods[] =
{
{ "new", luaA_widget_new },
@ -364,6 +383,8 @@ const struct luaL_reg awesome_widget_meta[] =
{ "set", luaA_widget_set },
{ "name_set", luaA_widget_name_set },
{ "name_get", luaA_widget_name_get },
{ "visible_set", luaA_widget_visible_set },
{ "visible_get", luaA_widget_visible_get },
{ "__gc", luaA_widget_gc },
{ "__eq", luaA_widget_eq },
{ "__tostring", luaA_widget_tostring },