]> Dogcows Code - chaz/openbox/blob - openbox/propwin.c
debug print
[chaz/openbox] / openbox / propwin.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 propwin.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
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.
11
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.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "propwin.h"
21 #include "openbox.h"
22
23 typedef struct _ObPropWin ObPropWin;
24 typedef struct _ObPropWinData ObPropWinData;
25
26 struct _ObPropWinData
27 {
28 GSList *clients;
29 };
30
31 struct _ObPropWin
32 {
33 Window win;
34 ObPropWinData data[OB_NUM_PROPWIN_TYPES];
35 };
36
37 /*! A hash table that maps a window to an ObPropWin */
38 static GHashTable *propwin_map;
39
40 static guint window_hash(Window *w) { return *w; }
41 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
42
43 void propwin_startup(gboolean reconfig)
44 {
45 if (!reconfig)
46 propwin_map = g_hash_table_new_full((GHashFunc)window_hash,
47 (GEqualFunc)window_comp,
48 NULL,
49 g_free);
50 }
51
52 void propwin_shutdown(gboolean reconfig)
53 {
54 if (!reconfig)
55 g_hash_table_destroy(propwin_map);
56 else
57 g_assert(g_hash_table_size(propwin_map) == 0);
58 }
59
60 void propwin_add(Window win, ObPropWinType type, struct _ObClient *client)
61 {
62 ObPropWin *p;
63
64 if (!win) return;
65
66 g_assert(client);
67 g_assert(type < OB_NUM_PROPWIN_TYPES);
68
69 p = g_hash_table_lookup(propwin_map, &win);
70 if (!p) {
71 p = g_new0(ObPropWin, 1);
72 p->win = win;
73 g_hash_table_insert(propwin_map, &p->win, p);
74 /* get property changes on this window */
75 XSelectInput(ob_display, win, PropertyChangeMask);
76 } else
77 g_assert(g_slist_find(p->data[type].clients, client) == NULL);
78
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);
82
83 /* add it to the clients list */
84 p->data[type].clients = g_slist_prepend(p->data[type].clients, client);
85 }
86
87 void propwin_remove(Window win, ObPropWinType type, struct _ObClient *client)
88 {
89 ObPropWin *p;
90
91 if (!win) return;
92
93 p = g_hash_table_lookup(propwin_map, &win);
94 g_assert(p);
95
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);
99
100 /* no more clients left for this type */
101 if (p->data[type].clients == NULL) {
102 guint i;
103 gboolean none = TRUE;
104
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
108 window */
109
110 if (none) {
111 /* don't get events for this window any more */
112 XSelectInput(ob_display, win, NoEventMask);
113 g_hash_table_remove(propwin_map, &win);
114 }
115 }
116 }
117
118 GSList* propwin_get_clients(Window win, ObPropWinType type)
119 {
120 ObPropWin *p = g_hash_table_lookup(propwin_map, &win);
121 if (p)
122 return p->data[type].clients;
123 else
124 return NULL;
125 }
This page took 0.040742 seconds and 5 git commands to generate.