From f84e66ddc65b47e27574842405dbcdaa8b5a87e2 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Tue, 24 Jun 2008 14:16:37 +0200 Subject: [PATCH] Avoid lists of tag/client pairs, use an array per tag. Signed-off-by: Pierre Habouzit Signed-off-by: Julien Danjou --- structs.h | 14 +++----------- tag.c | 30 ++++++++---------------------- tag.h | 3 +-- 3 files changed, 12 insertions(+), 35 deletions(-) diff --git a/structs.h b/structs.h index 211641b8e..a31fabce0 100644 --- a/structs.h +++ b/structs.h @@ -318,6 +318,7 @@ struct client_t /** Next and previous clients */ client_t *prev, *next; }; +DO_ARRAY(client_t *, client, DO_NOTHING); struct client_node_t { @@ -346,18 +347,11 @@ struct _tag_t int nmaster; /** Number of columns in tile layout */ int ncol; + /** clients in this tag */ + client_array_t clients; }; ARRAY_TYPE(tag_t *, tag); -/** Tag client link type */ -struct tag_client_node_t -{ - tag_t *tag; - client_t *client; - /** Next and previous tag_client_nodes */ - tag_client_node_t *prev, *next; -}; - /** Padding type */ typedef struct { @@ -431,8 +425,6 @@ struct awesome_t client_node_t *focus; /** Stack client history */ client_node_t *stack; - /** Link between tags and clients */ - tag_client_node_t *tclink; /** Command line passed to awesome */ char *argv; /** Last XMotionEvent coords */ diff --git a/tag.c b/tag.c index fb2c49e42..6dd73c92a 100644 --- a/tag.c +++ b/tag.c @@ -109,17 +109,11 @@ tag_append_to_screen(tag_t *tag, int screen) void tag_client(client_t *c, tag_t *t) { - tag_client_node_t *tc; - /* don't tag twice */ if(is_client_tagged(c, t)) return; - tc = p_new(tag_client_node_t, 1); - tc->client = c; - tc->tag = t; - tag_client_node_list_push(&globalconf.tclink, tc); - + client_array_append(&t->clients, c); client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); globalconf.screens[c->screen].need_arrange = true; @@ -132,17 +126,14 @@ tag_client(client_t *c, tag_t *t) void untag_client(client_t *c, tag_t *t) { - tag_client_node_t *tc; - - for(tc = globalconf.tclink; tc; tc = tc->next) - if(tc->client == c && tc->tag == t) + for(int i = 0; i < t->clients.len; i++) + if(t->clients.tab[i] == c) { - tag_client_node_list_detach(&globalconf.tclink, tc); - p_delete(&tc); + client_array_take(&t->clients, i); client_saveprops(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); - globalconf.screens[c->screen].need_arrange = True; - break; + globalconf.screens[c->screen].need_arrange = true; + return; } } @@ -154,13 +145,8 @@ untag_client(client_t *c, tag_t *t) bool is_client_tagged(client_t *c, tag_t *t) { - tag_client_node_t *tc; - - if(!c) - return false; - - for(tc = globalconf.tclink; tc; tc = tc->next) - if(tc->client == c && tc->tag == t) + for(int i = 0; i < t->clients.len; i++) + if (t->clients.tab[i] == c) return true; return false; diff --git a/tag.h b/tag.h index 1d74820d2..fe533cb17 100644 --- a/tag.h +++ b/tag.h @@ -34,6 +34,7 @@ tag_t *tag_new(const char *, layout_t *, double, int, int); static inline void tag_delete(tag_t **tag) { + client_array_wipe(&(*tag)->clients); p_delete(&(*tag)->name); p_delete(tag); } @@ -50,7 +51,5 @@ int luaA_tag_userdata_new(lua_State *, tag_t *); DO_RCNT(tag_t, tag, tag_delete) ARRAY_FUNCS(tag_t *, tag, tag_unref); -DO_SLIST(tag_client_node_t, tag_client_node, p_delete) - #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80