From: Dana Jansens Date: Fri, 29 Jul 2011 20:57:55 +0000 (-0400) Subject: Pass a user data to the client_set_reduce/expand function which is given to the X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=7ecc846358882c5e50a404d41bc66a638cd07e51;p=dana%2Fopenbox.git Pass a user data to the client_set_reduce/expand function which is given to the callback. This lets us pass the filter's context in to its test function along with the client window, so it can make an intelligent decision about adding/removing the client from the current set. --- diff --git a/openbox/action_filter.c b/openbox/action_filter.c index e5e9b9ba..0d6c08de 100644 --- a/openbox/action_filter.c +++ b/openbox/action_filter.c @@ -143,11 +143,11 @@ void action_filter_unref(ObActionFilter *f) void action_filter_expand(ObActionFilter *f, struct _ObClientSet *set) { g_return_if_fail(f != NULL); - client_set_expand(set, f->def->expand); + client_set_expand(set, f->def->expand, f->data); } void action_filter_reduce(ObActionFilter *f, struct _ObClientSet *set) { g_return_if_fail(f != NULL); - client_set_reduce(set, f->def->reduce); + client_set_reduce(set, f->def->reduce, f->data); } diff --git a/openbox/client_set.c b/openbox/client_set.c index fd9880a3..866feee4 100644 --- a/openbox/client_set.c +++ b/openbox/client_set.c @@ -113,23 +113,34 @@ ObClientSet* client_set_intersection(ObClientSet *a, ObClientSet *b) return a; } +struct ObClientSetForeachReduce { + ObClientSetReduceFunc f; + gpointer data; +}; + static gboolean foreach_reduce(gpointer k, gpointer v, gpointer u) { ObClient *c = v; - ObClientSetReduceFunc f = u; - return f(c); + struct ObClientSetForeachReduce *d = u; + return d->f(c, d->data); } -ObClientSet* client_set_reduce(ObClientSet *set, ObClientSetReduceFunc f) +ObClientSet* client_set_reduce(ObClientSet *set, ObClientSetReduceFunc f, + gpointer data) { + struct ObClientSetForeachReduce d; + g_return_val_if_fail(set != NULL, NULL); g_return_val_if_fail(f != NULL, NULL); - g_hash_table_foreach_remove(set->h, foreach_reduce, f); + d.f = f; + d.data = data; + g_hash_table_foreach_remove(set->h, foreach_reduce, &d); return set; } -ObClientSet* client_set_expand(ObClientSet *set, ObClientSetExpandFunc f) +ObClientSet* client_set_expand(ObClientSet *set, ObClientSetExpandFunc f, + gpointer data) { GList *it; @@ -138,7 +149,7 @@ ObClientSet* client_set_expand(ObClientSet *set, ObClientSetExpandFunc f) for (it = client_list; it; it = g_list_next(it)) { ObClient *c = it->data; - if (!g_hash_table_lookup(set->h, &c->window) && f(c)) + if (!g_hash_table_lookup(set->h, &c->window) && f(c, data)) g_hash_table_insert(set->h, &c->window, c); } return set; diff --git a/openbox/client_set.h b/openbox/client_set.h index 96b41e74..3537018a 100644 --- a/openbox/client_set.h +++ b/openbox/client_set.h @@ -22,8 +22,8 @@ struct _ObClient; typedef struct _ObClientSet ObClientSet; -typedef gboolean (*ObClientSetReduceFunc)(struct _ObClient *c); -typedef gboolean (*ObClientSetExpandFunc)(struct _ObClient *c); +typedef gboolean (*ObClientSetReduceFunc)(struct _ObClient *c, gpointer data); +typedef gboolean (*ObClientSetExpandFunc)(struct _ObClient *c, gpointer data); /*! Returns a new set of clients without anything in it. */ ObClientSet* client_set_empty(void); @@ -48,9 +48,11 @@ ObClientSet* client_set_intersection(ObClientSet *a, ObClientSet *b); /*! Reduce a set of clients. The function @f is called for each client currently in the set. For each client that it returns TRUE, the client will be removed from the set. */ -ObClientSet* client_set_reduce(ObClientSet *set, ObClientSetReduceFunc f); +ObClientSet* client_set_reduce(ObClientSet *set, ObClientSetReduceFunc f, + gpointer data); /*! Expand a set of clients. The function @f is called for each client not currently in the set. For each client that it returns TRUE, the client will be added to the set. */ -ObClientSet* client_set_expand(ObClientSet *set, ObClientSetExpandFunc f); +ObClientSet* client_set_expand(ObClientSet *set, ObClientSetExpandFunc f, + gpointer data);