X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=render%2Finstance.c;h=b867815c31c5096b44b9b7a6b2470fef8a6402f6;hb=972e1fc5a32e7d798fb3023012e73af20b5b03c7;hp=bd2b537e371268a9d7490b030aa75b3f3fe8eee2;hpb=3f32dfa87e08556d7f6a58efab9b7479e515be26;p=chaz%2Fopenbox diff --git a/render/instance.c b/render/instance.c index bd2b537e..b867815c 100644 --- a/render/instance.c +++ b/render/instance.c @@ -1,13 +1,64 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + instance.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 "render.h" #include "instance.h" static RrInstance *definst = NULL; -void RrTrueColorSetup (RrInstance *inst); -void RrPseudoColorSetup (RrInstance *inst); +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 == *(gint*)n) + g_message("color %d has %d references", c->id, c->refcount); +} + +void print_refs(gint id) +{ + g_hash_table_foreach(RrColorHash(definst), f, &id); +} +#endif RrInstance* RrInstanceNew (Display *display, gint screen) { + g_type_init(); /* supposedly needed for pango but seems to work without */ + definst = g_new (RrInstance, 1); definst->display = display; definst->screen = screen; @@ -15,9 +66,13 @@ RrInstance* RrInstanceNew (Display *display, gint screen) definst->depth = DefaultDepth(display, screen); definst->visual = DefaultVisual(display, screen); definst->colormap = DefaultColormap(display, screen); + definst->pango = pango_xft_get_context(display, 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); @@ -36,9 +91,9 @@ RrInstance* RrInstanceNew (Display *display, gint screen) return definst; } -void RrTrueColorSetup (RrInstance *inst) +static void RrTrueColorSetup (RrInstance *inst) { - unsigned long red_mask, green_mask, blue_mask; + gulong red_mask, green_mask, blue_mask; XImage *timage = NULL; timage = XCreateImage(inst->display, inst->visual, inst->depth, @@ -64,15 +119,14 @@ void RrTrueColorSetup (RrInstance *inst) XFree(timage); } -#define RrPseudoNcolors(isnt) (1 << (inst->pseudo_bpc * 3)) +#define RrPseudoNcolors(inst) (1 << (inst->pseudo_bpc * 3)) -void RrPseudoColorSetup (RrInstance *inst) +static void RrPseudoColorSetup (RrInstance *inst) { XColor icolors[256]; - int tr, tg, tb, n, r, g, b, i, incolors, ii; - unsigned long dev; - int cpc, _ncolors; - g_message("Initializing PseudoColor RenderControl\n"); + gint tr, tg, tb, n, r, g, b, i, incolors, ii; + gulong dev; + gint cpc, _ncolors; /* determine the number of colors and the bits-per-color */ inst->pseudo_bpc = 2; /* XXX THIS SHOULD BE A USER OPTION */ @@ -80,7 +134,7 @@ void RrPseudoColorSetup (RrInstance *inst) _ncolors = RrPseudoNcolors(inst); if (_ncolors > 1 << inst->depth) { - g_warning("PseudoRenderControl: Invalid colormap size. Resizing.\n"); + g_message("Invalid colormap size. Resizing."); inst->pseudo_bpc = 1 << (inst->depth/3) >> 3; _ncolors = 1 << (inst->pseudo_bpc * 3); } @@ -92,9 +146,9 @@ void RrPseudoColorSetup (RrInstance *inst) for (n = 0, r = 0; r < cpc; r++) for (g = 0; g < cpc; g++) for (b = 0; b < cpc; b++, n++) { - tr = (int)(((float)(r)/(float)(cpc-1)) * 0xFF); - tg = (int)(((float)(g)/(float)(cpc-1)) * 0xFF); - tb = (int)(((float)(b)/(float)(cpc-1)) * 0xFF); + tr = (gint)(((gfloat)(r)/(gfloat)(cpc-1)) * 0xFF); + tg = (gint)(((gfloat)(g)/(gfloat)(cpc-1)) * 0xFF); + tb = (gint)(((gfloat)(b)/(gfloat)(cpc-1)) * 0xFF); inst->pseudo_colors[n].red = tr | tr << 8; inst->pseudo_colors[n].green = tg | tg << 8; inst->pseudo_colors[n].blue = tb | tb << 8; @@ -121,7 +175,7 @@ void RrPseudoColorSetup (RrInstance *inst) /* try match unallocated ones */ for (i = 0; i < _ncolors; i++) { if (!inst->pseudo_colors[i].flags) { /* if it wasn't allocated... */ - unsigned long closest = 0xffffffff, close = 0; + gulong closest = 0xffffffff, close = 0; for (ii = 0; ii < incolors; ii++) { /* find deviations */ r = (inst->pseudo_colors[i].red - icolors[ii].red) & 0xff; @@ -158,6 +212,9 @@ void RrInstanceFree (RrInstance *inst) if (inst) { if (inst == definst) definst = NULL; g_free(inst->pseudo_colors); + g_hash_table_destroy(inst->color_hash); + g_object_unref(inst->pango); + g_free(inst); } } @@ -245,3 +302,8 @@ XColor *RrPseudoColors (const RrInstance *inst) { return (inst ? inst : definst)->pseudo_colors; } + +GHashTable* RrColorHash (const RrInstance *inst) +{ + return (inst ? inst : definst)->color_hash; +}