diff --git a/lua.c b/lua.c index b00acd20..3168091d 100644 --- a/lua.c +++ b/lua.c @@ -645,7 +645,8 @@ luaA_parserc(const char *confpatharg) /* Assure there's at least one tag */ for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) if(!globalconf.screens[screen].tags.len) - tag_append_to_screen(tag_new("default", sizeof("default")-1, layout_tile, 0.5, 1, 0), screen); + tag_append_to_screen(tag_new("default", sizeof("default")-1, layout_tile, 0.5, 1, 0), + &globalconf.screens[screen]); p_delete(&confpath); } diff --git a/screen.c b/screen.c index b7c3cede..9ed55487 100644 --- a/screen.c +++ b/screen.c @@ -308,6 +308,8 @@ luaA_screen_newindex(lua_State *L) size_t len; const char *buf = luaL_checklstring(L, 2, &len); screen_t *s; + tag_t **tag; + int i; s = lua_touserdata(L, 1); @@ -322,6 +324,27 @@ luaA_screen_newindex(lua_State *L) ewmh_update_workarea(screen_virttophys(s->index)); + break; + case A_TK_TAGS: + luaA_checktable(L, 3); + + /* remove current tags */ + for(i = 0; i < s->tags.len; i++) + s->tags.tab[i]->screen = SCREEN_UNDEF; + + tag_array_wipe(&s->tags); + tag_array_init(&s->tags); + + s->need_arrange = true; + + /* push new tags */ + lua_pushnil(L); + while(lua_next(L, 3)) + { + tag = luaA_checkudata(L, -1, "tag"); + tag_append_to_screen(*tag, s); + lua_pop(L, 1); + } break; default: return 0; diff --git a/tag.c b/tag.c index 2f20c6ac..b4d540a6 100644 --- a/tag.c +++ b/tag.c @@ -91,16 +91,16 @@ tag_new(const char *name, ssize_t len, layout_t *layout, double mwfact, int nmas * \param screen the screen id */ void -tag_append_to_screen(tag_t *tag, int screen) +tag_append_to_screen(tag_t *tag, screen_t *s) { - int phys_screen = screen_virttophys(screen); + int phys_screen = screen_virttophys(s->index); - tag->screen = screen; - tag_array_append(&globalconf.screens[screen].tags, tag_ref(&tag)); + tag->screen = s->index; + tag_array_append(&s->tags, tag_ref(&tag)); ewmh_update_net_numbers_of_desktop(phys_screen); ewmh_update_net_desktop_names(phys_screen); ewmh_update_workarea(phys_screen); - widget_invalidate_cache(screen, WIDGET_CACHE_TAGS); + widget_invalidate_cache(s->index, WIDGET_CACHE_TAGS); } /** Remove a tag from screen. Tag must be on a screen and have no clients. @@ -137,6 +137,7 @@ tag_client(client_t *c, tag_t *t) if(is_client_tagged(c, t)) return; + tag_ref(&t); client_array_append(&t->clients, c); client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); @@ -153,6 +154,7 @@ untag_client(client_t *c, tag_t *t) for(int i = 0; i < t->clients.len; i++) if(t->clients.tab[i] == c) { + tag_unref(&t); client_array_take(&t->clients, i); client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); @@ -401,13 +403,7 @@ luaA_tag_newindex(lua_State *L) screen = SCREEN_UNDEF; if((*tag)->screen != SCREEN_UNDEF) - { - if((*tag)->clients.len) - luaL_error(L, "unable to remove tag %s from screen %d, it still has clients", - (*tag)->name, (*tag)->screen); - else - tag_remove_from_screen(*tag); - } + tag_remove_from_screen(*tag); if(screen != SCREEN_UNDEF) { @@ -415,7 +411,7 @@ luaA_tag_newindex(lua_State *L) luaL_error(L, "a tag with the name `%s' is already on screen %d", (*tag)->name, screen); - tag_append_to_screen(*tag, screen); + tag_append_to_screen(*tag, &globalconf.screens[screen]); } break; case A_TK_LAYOUT: diff --git a/tag.h b/tag.h index a0c0ed94..87335f1b 100644 --- a/tag.h +++ b/tag.h @@ -44,7 +44,7 @@ void tag_client(client_t *, tag_t *); void untag_client(client_t *, tag_t *); bool is_client_tagged(client_t *, tag_t *); void tag_view_only_byindex(int, int); -void tag_append_to_screen(tag_t *, int); +void tag_append_to_screen(tag_t *, screen_t *); int luaA_tag_userdata_new(lua_State *, tag_t *); DO_RCNT(tag_t, tag, tag_delete)