]> Dogcows Code - chaz/openbox/blob - openbox/group.c
Merge branch 'master' into chaz
[chaz/openbox] / 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-2007 Dana 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 static GHashTable *group_map;
23
24 static guint window_hash(Window *w) { return *w; }
25 static gboolean window_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)window_hash,
32 (GEqualFunc)window_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_slice_new(ObGroup);
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_slice_free(ObGroup, self);
65 }
66 }
This page took 0.035499 seconds and 4 git commands to generate.