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.
25 typedef struct _ObPropWin ObPropWin;
26 typedef struct _ObPropWinData ObPropWinData;
36 ObPropWinData data[OB_NUM_PROPWIN_TYPES];
39 /*! A hash table that maps a window to an ObPropWin */
40 static GHashTable *propwin_map;
42 static guint window_hash(Window *w) { return *w; }
43 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
45 void propwin_startup(gboolean reconfig)
48 propwin_map = g_hash_table_new_full((GHashFunc)window_hash,
49 (GEqualFunc)window_comp,
54 void propwin_shutdown(gboolean reconfig)
57 g_hash_table_destroy(propwin_map);
59 g_assert(g_hash_table_size(propwin_map) == 0);
62 void propwin_add(Window win, ObPropWinType type, ObClient *client)
69 g_assert(type < OB_NUM_PROPWIN_TYPES);
71 p = g_hash_table_lookup(propwin_map, &win);
73 p = g_new0(ObPropWin, 1);
75 g_hash_table_insert(propwin_map, &p->win, p);
76 /* get property changes on this window */
77 XSelectInput(ob_display, win, PropertyChangeMask);
79 g_assert(g_slist_find(p->data[type].clients, client) == NULL);
81 if (p->data[type].clients != NULL)
82 ob_debug("Client %s is using a property window 0x%x that is already "
83 "in use\n", client->title, win);
85 /* add it to the clients list */
86 p->data[type].clients = g_slist_prepend(p->data[type].clients, client);
89 void propwin_remove(Window win, ObPropWinType type, ObClient *client)
95 p = g_hash_table_lookup(propwin_map, &win);
98 /* remove it to the clients list */
99 g_assert(g_slist_find(p->data[type].clients, client) != NULL);
100 p->data[type].clients = g_slist_remove(p->data[type].clients, client);
102 /* no more clients left for this type */
103 if (p->data[type].clients == NULL) {
105 gboolean none = TRUE;
107 for (i = 0; i < OB_NUM_PROPWIN_TYPES; ++i)
108 if (p->data[i].clients != NULL)
109 none = FALSE; /* another type still has a client for this
113 /* don't get events for this window any more */
114 XSelectInput(ob_display, win, NoEventMask);
115 g_hash_table_remove(propwin_map, &win);
120 GSList* propwin_get_clients(Window win, ObPropWinType type)
122 ObPropWin *p = g_hash_table_lookup(propwin_map, &win);
124 return p->data[type].clients;