]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/propwin.c
support for _NET_WM_USER_TIME_WINDOW round 2 ! yay abstraction
[mikachu/openbox.git] / 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     /* add it to the clients list */
80     p->data[type].clients = g_slist_prepend(p->data[type].clients, client);
81 }
82
83 void propwin_remove(Window win, ObPropWinType type, struct _ObClient *client)
84 {
85     ObPropWin *p;
86
87     if (!win) return;
88
89     p = g_hash_table_lookup(propwin_map, &win);
90     g_assert(p);
91
92     /* remove it to the clients list */
93     g_assert(g_slist_find(p->data[type].clients, client) != NULL);
94     p->data[type].clients = g_slist_remove(p->data[type].clients, client);
95
96     /* no more clients left for this type */
97     if (p->data[type].clients == NULL) {
98         guint i;
99         gboolean none = TRUE;
100
101         for (i = 0; i < OB_NUM_PROPWIN_TYPES; ++i)
102             if (p->data[i].clients != NULL)
103                 none = FALSE; /* another type still has a client for this
104                                  window */
105
106         if (none) {
107             /* don't get events for this window any more */
108             XSelectInput(ob_display, win, NoEventMask);
109             g_hash_table_remove(propwin_map, &win);
110         }
111     }
112 }
113
114 GSList* propwin_get_clients(Window win, ObPropWinType type)
115 {
116     ObPropWin *p = g_hash_table_lookup(propwin_map, &win);
117     if (p)
118         return p->data[type].clients;
119     else
120         return NULL;
121 }