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.
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);
}
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;
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;
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);
/*! 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);