screen: make tags array overwritable

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-12 14:46:22 +02:00
parent 530f27e4a1
commit 40c455046b
4 changed files with 35 additions and 15 deletions

3
lua.c
View File

@ -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);
}

View File

@ -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;

20
tag.c
View File

@ -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);
}
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:

2
tag.h
View File

@ -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)