track window groups
[dana/openbox.git] / openbox / group.c
1 #include "group.h"
2 #include "client.h"
3
4 GHashTable *group_map = NULL;
5
6 static guint map_hash(Window *w) { return *w; }
7 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
8
9 void group_startup()
10 {
11     group_map = g_hash_table_new((GHashFunc)map_hash,
12                                  (GEqualFunc)map_key_comp);
13 }
14
15 void group_shutdown()
16 {
17     g_hash_table_destroy(group_map);
18 }
19
20 Group *group_add(Window leader, Client *client)
21 {
22     Group *self;
23
24     self = g_hash_table_lookup(group_map, &leader);
25     if (self == NULL) {
26         self = g_new(Group, 1);
27         self->leader = leader;
28         self->members = NULL;
29         g_hash_table_insert(group_map, &self->leader, self);
30         g_message("NEW GROUP FOR %lx", leader);
31     } else
32         g_message("REUSING GROUP FOR %lx", leader);
33
34     self->members = g_slist_append(self->members, client);
35
36     return self;
37 }
38
39 void group_remove(Group *self, Client *client)
40 {
41     self->members = g_slist_remove(self->members, client);
42     if (self->members == NULL) {
43         g_hash_table_remove(group_map, &self->leader);
44         g_free(self);
45     }
46 }