1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 propwin.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
23 typedef struct _ObPropWin ObPropWin;
24 typedef struct _ObPropWinData ObPropWinData;
34 ObPropWinData data[OB_NUM_PROPWIN_TYPES];
37 /*! A hash table that maps a window to an ObPropWin */
38 static GHashTable *propwin_map;
40 static guint window_hash(Window *w) { return *w; }
41 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
43 void propwin_startup(gboolean reconfig)
46 propwin_map = g_hash_table_new_full((GHashFunc)window_hash,
47 (GEqualFunc)window_comp,
52 void propwin_shutdown(gboolean reconfig)
55 g_hash_table_destroy(propwin_map);
57 g_assert(g_hash_table_size(propwin_map) == 0);
60 void propwin_add(Window win, ObPropWinType type, struct _ObClient *client)
67 g_assert(type < OB_NUM_PROPWIN_TYPES);
69 p = g_hash_table_lookup(propwin_map, &win);
71 p = g_new0(ObPropWin, 1);
73 g_hash_table_insert(propwin_map, &p->win, p);
74 /* get property changes on this window */
75 XSelectInput(ob_display, win, PropertyChangeMask);
77 g_assert(g_slist_find(p->data[type].clients, client) == NULL);
79 if (p->data[type].clients != NULL)
80 ob_debug("Client %s is using a property window 0x%x that is already "
81 "in use\n", client->title, win);
83 /* add it to the clients list */
84 p->data[type].clients = g_slist_prepend(p->data[type].clients, client);
87 void propwin_remove(Window win, ObPropWinType type, struct _ObClient *client)
93 p = g_hash_table_lookup(propwin_map, &win);
96 /* remove it to the clients list */
97 g_assert(g_slist_find(p->data[type].clients, client) != NULL);
98 p->data[type].clients = g_slist_remove(p->data[type].clients, client);
100 /* no more clients left for this type */
101 if (p->data[type].clients == NULL) {
103 gboolean none = TRUE;
105 for (i = 0; i < OB_NUM_PROPWIN_TYPES; ++i)
106 if (p->data[i].clients != NULL)
107 none = FALSE; /* another type still has a client for this
111 /* don't get events for this window any more */
112 XSelectInput(ob_display, win, NoEventMask);
113 g_hash_table_remove(propwin_map, &win);
118 GSList* propwin_get_clients(Window win, ObPropWinType type)
120 ObPropWin *p = g_hash_table_lookup(propwin_map, &win);
122 return p->data[type].clients;