Provide operations to get the size of a ObClientSet, and get the clients in it. Also...
authorDana Jansens <danakj@orodu.net>
Wed, 3 Aug 2011 20:57:21 +0000 (16:57 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Oct 2011 22:55:15 +0000 (18:55 -0400)
openbox/client_set.c
openbox/client_set.h

index fde8bbefcd0e0a9f24b19ab9999f658348c48bc9..e1aa194fd23caf693acf689d3ad00e56cebb206b 100644 (file)
@@ -320,6 +320,7 @@ gboolean client_set_test_boolean(const ObClientSet *set)
 
 gboolean client_set_contains(const ObClientSet *set, struct _ObClient *c)
 {
+    if (!c) return FALSE;
     if (set->all) return TRUE;
     if (!set->h) return FALSE;
     return g_hash_table_lookup(set->h, &c->window) != NULL;
@@ -337,9 +338,9 @@ typedef struct {
 
 void foreach_func(gpointer k, gpointer v, gpointer u)
 {
-    const ObClientSetForeachData *const d = u;
-    if (!d->runnig) return;
-    d->runnig = d->func.foreach((ObClient*)v, d->data);
+    ObClientSetForeachData *const d = u;
+    if (!d->running) return;
+    d->running = d->func.foreach((ObClient*)v, d->data);
 }
 
 void client_set_foreach(const ObClientSet *set, ObClientSetForeachFunc func,
@@ -363,7 +364,7 @@ void client_set_foreach(const ObClientSet *set, ObClientSetForeachFunc func,
 
 void run_func(gpointer k, gpointer v, gpointer u)
 {
-    const ObClientSetForeachData *const d = u;
+    ObClientSetForeachData *const d = u;
     if (!d->running) return;
     d->running = d->func.run((ObClient*)v, d->run, d->data);
 }
@@ -376,14 +377,34 @@ void client_set_run(const ObClientSet *set, const struct _ObActionListRun *run,
     if (set->all) {
         GList *it;
         for (it = client_list; it; it = g_list_next(it))
-            func(run, it->data, data);
+            func(it->data, run, data);
     }
     else if (set->h) {
         ObClientSetForeachData d;
         d.func.run = func;
         d.data = data;
         d.run = run;
-        d.running = FALSE;
+        d.running = TRUE;
         g_hash_table_foreach(set->h, run_func, &d);
     }
 }
+
+guint client_set_size(const ObClientSet *set)
+{
+    if (set->all)
+        return (unsigned)-1;
+    else if (!set->h)
+        return 0;
+    else
+        return g_hash_table_size(set->h);
+}
+
+GList *client_set_get_all(const ObClientSet *set)
+{
+    if (set->all)
+        return g_list_copy(client_list);
+    else if (!set->h)
+        return NULL;
+    else
+        return g_hash_table_get_values(set->h);
+}
index 4a522d9c1e7d70c524e86e68a8b9c233e1d4dae6..2d635c9b3951ec7811db71144901f96fe4997995 100644 (file)
@@ -89,3 +89,12 @@ void client_set_foreach(const ObClientSet *set, ObClientSetForeachFunc func,
   @data to the function along with the client. */
 void client_set_run(const ObClientSet *set, const struct _ObActionListRun *run,
                     ObClientSetRunFunc func, gpointer data);
+
+/*! Returns the size of the set.
+  In the special case where the set contains all windows, it returns
+  (unsigned)-1.  Otherwise it returns the number of windows in the set.
+*/
+guint client_set_size(const ObClientSet *set);
+
+/*! Returns a list of all clients in the set. */
+GList *client_set_get_all(const ObClientSet *set);