diff --git a/tag.c b/tag.c index 54c0f266..a0041f45 100644 --- a/tag.c +++ b/tag.c @@ -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); diff --git a/titlebar.c b/titlebar.c index 49611e55..788b1212 100644 --- a/titlebar.c +++ b/titlebar.c @@ -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;