]> icculus.org git repositories - dana/openbox.git/blob - openbox/group.c
move the keyboard and mouse plugins into the kernel for mucho sexiness.
[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 ObGroup *group_add(Window leader, ObClient *client)
21 {
22     ObGroup *self;
23
24     self = g_hash_table_lookup(group_map, &leader);
25     if (self == NULL) {
26         self = g_new(ObGroup, 1);
27         self->leader = leader;
28         self->members = NULL;
29         g_hash_table_insert(group_map, &self->leader, self);
30     }
31
32     self->members = g_slist_append(self->members, client);
33
34     return self;
35 }
36
37 void group_remove(ObGroup *self, ObClient *client)
38 {
39     self->members = g_slist_remove(self->members, client);
40     if (self->members == NULL) {
41         g_hash_table_remove(group_map, &self->leader);
42         g_free(self);
43     }
44 }