]> Dogcows Code - chaz/openbox/blobdiff - openbox/group.c
track window groups
[chaz/openbox] / openbox / group.c
diff --git a/openbox/group.c b/openbox/group.c
new file mode 100644 (file)
index 0000000..69d2ccb
--- /dev/null
@@ -0,0 +1,46 @@
+#include "group.h"
+#include "client.h"
+
+GHashTable *group_map = NULL;
+
+static guint map_hash(Window *w) { return *w; }
+static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
+
+void group_startup()
+{
+    group_map = g_hash_table_new((GHashFunc)map_hash,
+                                 (GEqualFunc)map_key_comp);
+}
+
+void group_shutdown()
+{
+    g_hash_table_destroy(group_map);
+}
+
+Group *group_add(Window leader, Client *client)
+{
+    Group *self;
+
+    self = g_hash_table_lookup(group_map, &leader);
+    if (self == NULL) {
+        self = g_new(Group, 1);
+        self->leader = leader;
+        self->members = NULL;
+        g_hash_table_insert(group_map, &self->leader, self);
+        g_message("NEW GROUP FOR %lx", leader);
+    } else
+        g_message("REUSING GROUP FOR %lx", leader);
+
+    self->members = g_slist_append(self->members, client);
+
+    return self;
+}
+
+void group_remove(Group *self, Client *client)
+{
+    self->members = g_slist_remove(self->members, client);
+    if (self->members == NULL) {
+        g_hash_table_remove(group_map, &self->leader);
+        g_free(self);
+    }
+}
This page took 0.025365 seconds and 4 git commands to generate.