diff --git a/objects/client.c b/objects/client.c index 1a634de30..e4ba2dd27 100644 --- a/objects/client.c +++ b/objects/client.c @@ -1169,7 +1169,26 @@ luaA_client_tags(lua_State *L) { luaA_checktable(L, 2); for(int i = 0; i < tags->len; i++) - untag_client(c, tags->tab[i]); + { + /* Only untag if we aren't going to add this tag again */ + bool found = false; + lua_pushnil(L); + while(lua_next(L, 2)) + { + tag_t *t = lua_touserdata(L, -1); + /* Pop the value from lua_next */ + lua_pop(L, 1); + if (t != tags->tab[i]) + continue; + + /* Pop the key from lua_next */ + lua_pop(L, 1); + found = true; + break; + } + if(!found) + untag_client(c, tags->tab[i]); + } lua_pushnil(L); while(lua_next(L, 2)) tag_client(c); diff --git a/objects/tag.c b/objects/tag.c index 2901a01fe..7f08ae150 100644 --- a/objects/tag.c +++ b/objects/tag.c @@ -292,7 +292,26 @@ luaA_tag_clients(lua_State *L) { luaA_checktable(L, 2); foreach(c, tag->clients) - untag_client(*c, tag); + { + /* Only untag if we aren't going to add this tag again */ + bool found = false; + lua_pushnil(L); + while(lua_next(L, 2)) + { + client_t *tc = luaA_checkudata(L, -1, &client_class); + /* Pop the value from lua_next */ + lua_pop(L, 1); + if (tc != *c) + continue; + + /* Pop the key from lua_next */ + lua_pop(L, 1); + found = true; + break; + } + if(!found) + untag_client(*c, tag); + } lua_pushnil(L); while(lua_next(L, 2)) {