diff --git a/statusbar.c b/statusbar.c index 2fa8de1ca..103332922 100644 --- a/statusbar.c +++ b/statusbar.c @@ -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) diff --git a/structs.h b/structs.h index e8ba911d4..b9decc388 100644 --- a/structs.h +++ b/structs.h @@ -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 diff --git a/widget.c b/widget.c index af77ec721..4f74c1ff8 100644 --- a/widget.c +++ b/widget.c @@ -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 },