diff --git a/client.c b/client.c index 8799fb1b..9335e952 100644 --- a/client.c +++ b/client.c @@ -105,7 +105,7 @@ client_maybevisible(client_t *c, screen_t *screen) return true; foreach(tag, screen->tags) - if((*tag)->selected && is_client_tagged(c, *tag)) + if(tag_get_selected(*tag) && is_client_tagged(c, *tag)) return true; } return false; diff --git a/ewmh.c b/ewmh.c index 294766bd..23c5e016 100644 --- a/ewmh.c +++ b/ewmh.c @@ -197,14 +197,13 @@ ewmh_update_net_current_desktop(int phys_screen) void ewmh_update_net_desktop_names(int phys_screen) { - tag_array_t *tags = &globalconf.screens.tab[phys_screen].tags; buffer_t buf; buffer_inita(&buf, BUFSIZ); - for(int i = 0; i < tags->len; i++) + foreach(tag, globalconf.screens.tab[phys_screen].tags) { - buffer_adds(&buf, tags->tab[i]->name); + buffer_adds(&buf, tag_get_name(*tag)); buffer_addc(&buf, '\0'); } diff --git a/screen.c b/screen.c index 1ca78717..2ef532d0 100644 --- a/screen.c +++ b/screen.c @@ -274,7 +274,7 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool dotag, bool doresiz if(!c->issticky) /* add new tags */ foreach(new_tag, new_screen->tags) - if((*new_tag)->selected) + if(tag_get_selected(*new_tag)) { luaA_object_push(globalconf.L, *new_tag); tag_client(c); @@ -383,8 +383,8 @@ luaA_screen_tags(lua_State *L) luaA_checktable(L, 2); /* remove current tags */ - for(i = 0; i < s->tags.len; i++) - s->tags.tab[i]->screen = NULL; + foreach(tag, s->tags) + tag_set_screen(*tag, NULL); tag_array_wipe(&s->tags); tag_array_init(&s->tags); diff --git a/tag.c b/tag.c index f60321d2..dbfa3217 100644 --- a/tag.c +++ b/tag.c @@ -25,9 +25,24 @@ #include "ewmh.h" #include "widget.h" +/** Tag type */ +struct tag +{ + LUA_OBJECT_HEADER + /** Tag name */ + char *name; + /** Screen */ + screen_t *screen; + /** true if selected */ + bool selected; + /** clients in this tag */ + client_array_t clients; +}; + static lua_class_t tag_class; LUA_OBJECT_FUNCS(tag_class, tag_t, tag) + void tag_unref_simplified(tag_t **tag) { @@ -47,6 +62,15 @@ luaA_tag_gc(lua_State *L) return luaA_object_gc(L); } +OBJECT_EXPORT_PROPERTY(tag, tag_t, selected) +OBJECT_EXPORT_PROPERTY(tag, tag_t, name) + +void +tag_set_screen(tag_t *tag, screen_t *s) +{ + tag->screen = s; +} + /** View or unview a tag. * \param L The Lua VM state. * \param udx The index of the tag on the stack. diff --git a/tag.h b/tag.h index a8964dc5..63ffcd5f 100644 --- a/tag.h +++ b/tag.h @@ -24,20 +24,6 @@ #include "client.h" -/** Tag type */ -struct tag -{ - LUA_OBJECT_HEADER - /** Tag name */ - char *name; - /** Screen */ - screen_t *screen; - /** true if selected */ - bool selected; - /** clients in this tag */ - client_array_t clients; -}; - int tags_get_first_selected_index(screen_t *); void tag_client(client_t *); void untag_client(client_t *, tag_t *); @@ -50,5 +36,9 @@ ARRAY_FUNCS(tag_t *, tag, tag_unref_simplified) 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