]> icculus.org git repositories - dana/openbox.git/blob - openbox/group.c
937ebfd7ce3a1ff333a3321a02f6b1218aadd321
[dana/openbox.git] / openbox / group.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    group.c for the Openbox window manager
4    Copyright (c) 2003        Ben Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "group.h"
20 #include "client.h"
21
22 GHashTable *group_map = NULL;
23
24 static guint map_hash(Window *w) { return *w; }
25 static gboolean map_key_comp(Window *w1, Window *w2) { return *w1 == *w2; }
26
27 void group_startup(gboolean reconfig)
28 {
29     if (reconfig) return;
30
31     group_map = g_hash_table_new((GHashFunc)map_hash,
32                                  (GEqualFunc)map_key_comp);
33 }
34
35 void group_shutdown(gboolean reconfig)
36 {
37     if (reconfig) return;
38
39     g_hash_table_destroy(group_map);
40 }
41
42 ObGroup *group_add(Window leader, ObClient *client)
43 {
44     ObGroup *self;
45
46     self = g_hash_table_lookup(group_map, &leader);
47     if (self == NULL) {
48         self = g_new(ObGroup, 1);
49         self->leader = leader;
50         self->members = NULL;
51         g_hash_table_insert(group_map, &self->leader, self);
52     }
53
54     self->members = g_slist_append(self->members, client);
55
56     return self;
57 }
58
59 void group_remove(ObGroup *self, ObClient *client)
60 {
61     self->members = g_slist_remove(self->members, client);
62     if (self->members == NULL) {
63         g_hash_table_remove(group_map, &self->leader);
64         g_free(self);
65     }
66 }