titlebar: check for widget uniqness

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-18 16:37:26 +02:00
parent 471e0f1088
commit c7fc344cd3
2 changed files with 12 additions and 10 deletions

2
tag.c
View File

@ -267,12 +267,10 @@ luaA_tag_add(lua_State *L)
for(i = 0; i < globalconf.screens_info->nscreen; i++)
for(t = globalconf.screens[i].tags; t; t = t->next)
{
if(*tag == t)
luaL_error(L, "tag already on screen %d", i + 1);
else if(t->screen == screen && !a_strcmp((*tag)->name, t->name))
luaL_error(L, "a tag with the name `%s' is already on screen %d", t->name, i + 1);
}
(*tag)->screen = screen;
tag_append_to_screen(*tag, screen);

View File

@ -343,12 +343,19 @@ luaA_titlebar_widget_add(lua_State *L)
{
titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
widget_t **widget = luaA_checkudata(L, 2, "widget");
widget_node_t *w = p_new(widget_node_t, 1);
widget_node_t *witer, *w = p_new(widget_node_t, 1);
client_t *c;
if((*widget)->type == systray_new)
luaL_error(L, "cannot add systray widget to titlebar");
/* check that there is not already a widget with that name in the titlebar */
for(witer = (*tb)->widgets; witer; witer = witer->next)
if(witer->widget == *widget)
luaL_error(L, "widget `%s' is already on titlebar");
else if(!a_strcmp(witer->widget->name, (*widget)->name))
luaL_error(L, "a widget with name `%s' already on titlebar", witer->widget->name);
w->widget = *widget;
widget_node_list_append(&(*tb)->widgets, w);
widget_ref(widget);
@ -375,17 +382,14 @@ static int
luaA_titlebar_widget_get(lua_State *L)
{
titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
widget_node_t *widget;
int i = 1;
widget_node_t *witer;
lua_newtable(L);
for(widget = (*tb)->widgets; widget; widget = widget->next)
for(witer = (*tb)->widgets; witer; witer = witer->next)
{
luaA_widget_userdata_new(widget->widget);
/* ref again for the list */
widget_ref(&widget->widget);
lua_rawseti(L, -2, i++);
luaA_widget_userdata_new(witer->widget);
lua_setfield(L, -2, witer->widget->name);
}
return 1;