]> Dogcows Code - chaz/openbox/blobdiff - render/instance.c
recent changes
[chaz/openbox] / render / instance.c
index 26ea63c8b6a0ff8ae4504808845ddb4bc14f0469..f4a2441eefe2604a79ca0c744748ba2236ff0818 100644 (file)
@@ -1,3 +1,21 @@
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+   instance.c for the Openbox window manager
+   Copyright (c) 2003        Ben 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 "render.h"
 #include "instance.h"
 
@@ -6,6 +24,36 @@ static RrInstance *definst = NULL;
 static void RrTrueColorSetup (RrInstance *inst);
 static void RrPseudoColorSetup (RrInstance *inst);
 
+#ifdef DEBUG
+#include "color.h"
+#endif
+static void
+dest(gpointer data)
+{
+#ifdef DEBUG
+    RrColor *c = data;
+    if (c->refcount > 0)
+        g_error("color %d (%d,%d,%d) in hash table with %d "
+                "leftover references",
+                c->id, RrColorRed(c), RrColorGreen(c), RrColorBlue(c),
+                c->refcount);
+#endif
+}
+
+#if 0
+static void f(gpointer key, gpointer value, gpointer n)
+{
+    RrColor *c = value;
+    if (c->id == *(int*)n)
+        g_message("color %d has %d references", c->id, c->refcount);
+}
+
+void print_refs(int id)
+{
+    g_hash_table_foreach(RrColorHash(definst), f, &id);
+}
+#endif
+
 RrInstance* RrInstanceNew (Display *display, gint screen)
 {
     definst = g_new (RrInstance, 1);
@@ -18,6 +66,9 @@ RrInstance* RrInstanceNew (Display *display, gint screen)
 
     definst->pseudo_colors = NULL;
 
+    definst->color_hash = g_hash_table_new_full(g_int_hash, g_int_equal,
+                                                NULL, dest);
+
     switch (definst->visual->class) {
     case TrueColor:
         RrTrueColorSetup(definst);
@@ -157,6 +208,7 @@ void RrInstanceFree (RrInstance *inst)
     if (inst) {
         if (inst == definst) definst = NULL;
         g_free(inst->pseudo_colors);
+        g_hash_table_destroy(inst->color_hash);
     }
 }
 
@@ -244,3 +296,8 @@ XColor *RrPseudoColors (const RrInstance *inst)
 {
     return (inst ? inst : definst)->pseudo_colors;
 }
+
+GHashTable* RrColorHash (const RrInstance *inst)
+{
+    return (inst ? inst : definst)->color_hash;
+}
This page took 0.023945 seconds and 4 git commands to generate.