Pass a user data to the client_set_reduce/expand function which is given to the
authorDana Jansens <danakj@orodu.net>
Fri, 29 Jul 2011 20:57:55 +0000 (16:57 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Oct 2011 22:55:15 +0000 (18:55 -0400)
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.

openbox/action_filter.c
openbox/client_set.c
openbox/client_set.h

index e5e9b9baf16a6c4f24cf31149b4afe1984579d6f..0d6c08de969bdebde223782fe7aa7ab39c64440b 100644 (file)
@@ -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);
 }
index fd9880a33a240673ea8305627e76187babeb6c98..866feee4a76e40e98b7366b37fdc55cbb269361c 100644 (file)
@@ -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;
index 96b41e747d13dfe14e9f525dcfcdf65fb35ebbe1..3537018accfd5297a9c0ee1b5a334751e32249ba 100644 (file)
@@ -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);