diff options
| author | Dana Jansens <danakj@orodu.net> | 2007-05-09 17:58:58 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2007-05-09 17:58:58 +0000 |
| commit | 851555348ec39a01a0e150d2e12b71212b8d338b (patch) | |
| tree | bc118f364e184388b46d8efd53bbdf9d38c051bd /openbox/propwin.c | |
| parent | cdb108c76d20e8272bfbd15919e32e609d685322 (diff) | |
support for _NET_WM_USER_TIME_WINDOW round 2 ! yay abstraction
Diffstat (limited to 'openbox/propwin.c')
| -rw-r--r-- | openbox/propwin.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/openbox/propwin.c b/openbox/propwin.c new file mode 100644 index 00000000..0bf74b2a --- /dev/null +++ b/openbox/propwin.c @@ -0,0 +1,121 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + propwin.c for the Openbox window manager + Copyright (c) 2006 Mikael Magnusson + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "propwin.h" +#include "openbox.h" + +typedef struct _ObPropWin ObPropWin; +typedef struct _ObPropWinData ObPropWinData; + +struct _ObPropWinData +{ + GSList *clients; +}; + +struct _ObPropWin +{ + Window win; + ObPropWinData data[OB_NUM_PROPWIN_TYPES]; +}; + +/*! A hash table that maps a window to an ObPropWin */ +static GHashTable *propwin_map; + +static guint window_hash(Window *w) { return *w; } +static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; } + +void propwin_startup(gboolean reconfig) +{ + if (!reconfig) + propwin_map = g_hash_table_new_full((GHashFunc)window_hash, + (GEqualFunc)window_comp, + NULL, + g_free); +} + +void propwin_shutdown(gboolean reconfig) +{ + if (!reconfig) + g_hash_table_destroy(propwin_map); + else + g_assert(g_hash_table_size(propwin_map) == 0); +} + +void propwin_add(Window win, ObPropWinType type, struct _ObClient *client) +{ + ObPropWin *p; + + if (!win) return; + + g_assert(client); + g_assert(type < OB_NUM_PROPWIN_TYPES); + + p = g_hash_table_lookup(propwin_map, &win); + if (!p) { + p = g_new0(ObPropWin, 1); + p->win = win; + g_hash_table_insert(propwin_map, &p->win, p); + /* get property changes on this window */ + XSelectInput(ob_display, win, PropertyChangeMask); + } else + g_assert(g_slist_find(p->data[type].clients, client) == NULL); + + /* add it to the clients list */ + p->data[type].clients = g_slist_prepend(p->data[type].clients, client); +} + +void propwin_remove(Window win, ObPropWinType type, struct _ObClient *client) +{ + ObPropWin *p; + + if (!win) return; + + p = g_hash_table_lookup(propwin_map, &win); + g_assert(p); + + /* remove it to the clients list */ + g_assert(g_slist_find(p->data[type].clients, client) != NULL); + p->data[type].clients = g_slist_remove(p->data[type].clients, client); + + /* no more clients left for this type */ + if (p->data[type].clients == NULL) { + guint i; + gboolean none = TRUE; + + for (i = 0; i < OB_NUM_PROPWIN_TYPES; ++i) + if (p->data[i].clients != NULL) + none = FALSE; /* another type still has a client for this + window */ + + if (none) { + /* don't get events for this window any more */ + XSelectInput(ob_display, win, NoEventMask); + g_hash_table_remove(propwin_map, &win); + } + } +} + +GSList* propwin_get_clients(Window win, ObPropWinType type) +{ + ObPropWin *p = g_hash_table_lookup(propwin_map, &win); + if (p) + return p->data[type].clients; + else + return NULL; +} |
