Tag clients more intelligently (FS#700)

Before this commit, c:tags(tags) and t:clients(clients) first removed all
tags/clients and then added the new one.

This is now changed into only removing the tags/clients that have to be removed
and leaving the others in place. Hopefully, this avoids all kinds of weird
issues which we had.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2011-01-18 14:21:37 +01:00
parent 95ae751bad
commit 12c7e2852f
2 changed files with 40 additions and 2 deletions

View File

@ -1551,7 +1551,26 @@ luaA_client_tags(lua_State *L)
{ {
luaA_checktable(L, 2); luaA_checktable(L, 2);
for(int i = 0; i < tags->len; i++) for(int i = 0; i < tags->len; 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]); untag_client(c, tags->tab[i]);
}
lua_pushnil(L); lua_pushnil(L);
while(lua_next(L, 2)) while(lua_next(L, 2))
tag_client(c); tag_client(c);

19
tag.c
View File

@ -363,7 +363,26 @@ luaA_tag_clients(lua_State *L)
{ {
luaA_checktable(L, 2); luaA_checktable(L, 2);
foreach(c, tag->clients) foreach(c, tag->clients)
{
/* 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); untag_client(*c, tag);
}
lua_pushnil(L); lua_pushnil(L);
while(lua_next(L, 2)) while(lua_next(L, 2))
{ {