]> Dogcows Code - chaz/openbox/blob - openbox/propwin.c
remove trailing whitespace
[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 #include "client.h"
23 #include "debug.h"
24
25 typedef struct _ObPropWin ObPropWin;
26 typedef struct _ObPropWinData ObPropWinData;
27
28 struct _ObPropWinData
29 {
30 GSList *clients;
31 };
32
33 struct _ObPropWin
34 {
35 Window win;
36 ObPropWinData data[OB_NUM_PROPWIN_TYPES];
37 };
38
39 /*! A hash table that maps a window to an ObPropWin */
40 static GHashTable *propwin_map;
41
42 static guint window_hash(Window *w) { return *w; }
43 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
44
45 void propwin_startup(gboolean reconfig)
46 {
47 if (!reconfig)
48 propwin_map = g_hash_table_new_full((GHashFunc)window_hash,
49 (GEqualFunc)window_comp,
50 NULL,
51 g_free);
52 }
53
54 void propwin_shutdown(gboolean reconfig)
55 {
56 if (!reconfig)
57 g_hash_table_destroy(propwin_map);
58 else
59 g_assert(g_hash_table_size(propwin_map) == 0);
60 }
61
62 void propwin_add(Window win, ObPropWinType type, ObClient *client)
63 {
64 ObPropWin *p;
65
66 if (!win) return;
67
68 g_assert(client);
69 g_assert(type < OB_NUM_PROPWIN_TYPES);
70
71 p = g_hash_table_lookup(propwin_map, &win);
72 if (!p) {
73 p = g_new0(ObPropWin, 1);
74 p->win = win;
75 g_hash_table_insert(propwin_map, &p->win, p);
76 /* get property changes on this window */
77 XSelectInput(ob_display, win, PropertyChangeMask);
78 } else
79 g_assert(g_slist_find(p->data[type].clients, client) == NULL);
80
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);
84
85 /* add it to the clients list */
86 p->data[type].clients = g_slist_prepend(p->data[type].clients, client);
87 }
88
89 void propwin_remove(Window win, ObPropWinType type, ObClient *client)
90 {
91 ObPropWin *p;
92
93 if (!win) return;
94
95 p = g_hash_table_lookup(propwin_map, &win);
96 g_assert(p);
97
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);
101
102 /* no more clients left for this type */
103 if (p->data[type].clients == NULL) {
104 guint i;
105 gboolean none = TRUE;
106
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
110 window */
111
112 if (none) {
113 /* don't get events for this window any more */
114 XSelectInput(ob_display, win, NoEventMask);
115 g_hash_table_remove(propwin_map, &win);
116 }
117 }
118 }
119
120 GSList* propwin_get_clients(Window win, ObPropWinType type)
121 {
122 ObPropWin *p = g_hash_table_lookup(propwin_map, &win);
123 if (p)
124 return p->data[type].clients;
125 else
126 return NULL;
127 }
This page took 0.039943 seconds and 4 git commands to generate.