screen: fix tag removal/add

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-09-21 10:48:19 +02:00
parent 9f21570a05
commit 890e15fa19
3 changed files with 14 additions and 16 deletions

View File

@ -366,7 +366,7 @@ luaA_screen_module_index(lua_State *L)
return luaA_pushscreen(L, &globalconf.screens.tab[screen]);
}
/** Get or set screen tags.
/** Get screen tags.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
@ -377,23 +377,16 @@ luaA_screen_module_index(lua_State *L)
static int
luaA_screen_tags(lua_State *L)
{
int i;
screen_t *s = luaL_checkudata(L, 1, "screen");
if(lua_gettop(L) == 2)
{
luaA_checktable(L, 2);
/* remove current tags */
foreach(tag, s->tags)
tag_set_screen(*tag, NULL);
/* Detach all tags, but go backward since the array len will change */
for(int i = s->tags.len - 1; i >= 0; i--)
tag_remove_from_screen(s->tags.tab[i]);
tag_array_wipe(&s->tags);
tag_array_init(&s->tags);
s->need_reban = true;
/* push new tags */
lua_pushnil(L);
while(lua_next(L, 2))
tag_append_to_screen(L, -1, s);
@ -401,7 +394,7 @@ luaA_screen_tags(lua_State *L)
else
{
lua_createtable(L, s->tags.len, 0);
for(i = 0; i < s->tags.len; i++)
for(int i = 0; i < s->tags.len; i++)
{
luaA_object_push(L, s->tags.tab[i]);
lua_rawseti(L, -2, i + 1);

11
tag.c
View File

@ -121,7 +121,10 @@ tag_append_to_screen(lua_State *L, int udx, screen_t *s)
/* can't attach a tag twice */
if(tag->screen)
{
lua_remove(L, udx);
return;
}
int screen_index = screen_array_indexof(&globalconf.screens, s);
int phys_screen = screen_virttophys(screen_index);
@ -152,9 +155,12 @@ tag_append_to_screen(lua_State *L, int udx, screen_t *s)
/** Remove a tag from screen. Tag must be on a screen and have no clients.
* \param tag The tag to remove.
*/
static void
void
tag_remove_from_screen(tag_t *tag)
{
if(!tag->screen)
return;
int screen_index = screen_array_indexof(&globalconf.screens, tag->screen);
int phys_screen = screen_virttophys(screen_index);
tag_array_t *tags = &tag->screen->tags;
@ -431,8 +437,7 @@ luaA_tag_set_screen(lua_State *L, tag_t *tag)
luaA_checkscreen(screen);
}
if(tag->screen)
tag_remove_from_screen(tag);
tag_remove_from_screen(tag);
if(screen != -1)
tag_append_to_screen(L, -3, &globalconf.screens.tab[screen]);

2
tag.h
View File

@ -30,6 +30,7 @@ void untag_client(client_t *, tag_t *);
bool is_client_tagged(client_t *, tag_t *);
void tag_view_only_byindex(screen_t *, int);
void tag_append_to_screen(lua_State *, int, screen_t *);
void tag_remove_from_screen(tag_t *);
void tag_unref_simplified(tag_t **);
ARRAY_FUNCS(tag_t *, tag, tag_unref_simplified)
@ -38,7 +39,6 @@ void tag_class_setup(lua_State *);
bool tag_get_selected(tag_t *);
char *tag_get_name(tag_t *);
void tag_set_screen(tag_t *, screen_t *);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80