]> Dogcows Code - chaz/openbox/blobdiff - otk/gccache.cc
dont use a const_iterator
[chaz/openbox] / otk / gccache.cc
index d741c711663c4253ceadd760760051227bb1679d..554fd14329cc7c554b04ffbb3ed86cdb456a6160 100644 (file)
@@ -8,23 +8,25 @@ extern "C" {
 #include <stdio.h>
 }
 
+#include <algorithm>
+
 #include "gccache.hh"
 #include "color.hh"
-#include "util.hh"
+#include "assassin.hh"
 #include "screeninfo.hh"
 
 namespace otk {
 
-BGCCacheContext::~BGCCacheContext(void) {
+GCCacheContext::~GCCacheContext(void) {
   if (gc)
-    XFreeGC(OBDisplay::display, gc);
+    XFreeGC(**display, gc);
 }
 
 
-void BGCCacheContext::set(const BColor &_color,
-                          const XFontStruct * const _font,
-                          const int _function, const int _subwindow,
-                          int _linewidth) {
+void GCCacheContext::set(const Color &_color,
+                         const XFontStruct * const _font,
+                         const int _function, const int _subwindow,
+                         int _linewidth) {
   XGCValues gcv;
   pixel = gcv.foreground = _color.pixel();
   function = gcv.function = _function;
@@ -42,11 +44,11 @@ void BGCCacheContext::set(const BColor &_color,
     fontid = 0;
   }
 
-  XChangeGC(OBDisplay::display, gc, mask, &gcv);
+  XChangeGC(**display, gc, mask, &gcv);
 }
 
 
-void BGCCacheContext::set(const XFontStruct * const _font) {
+void GCCacheContext::set(const XFontStruct * const _font) {
   if (! _font) {
     fontid = 0;
     return;
@@ -54,28 +56,28 @@ void BGCCacheContext::set(const XFontStruct * const _font) {
 
   XGCValues gcv;
   fontid = gcv.font = _font->fid;
-  XChangeGC(OBDisplay::display, gc, GCFont, &gcv);
+  XChangeGC(**display, gc, GCFont, &gcv);
 }
 
 
-BGCCache::BGCCache(unsigned int screen_count)
+GCCache::GCCache(unsigned int screen_count)
   : context_count(128u), cache_size(16u), cache_buckets(8u * screen_count),
     cache_total_size(cache_size * cache_buckets) {
 
-  contexts = new BGCCacheContext*[context_count];
+  contexts = new GCCacheContext*[context_count];
   unsigned int i;
   for (i = 0; i < context_count; i++) {
-    contexts[i] = new BGCCacheContext();
+    contexts[i] = new GCCacheContext();
   }
 
-  cache = new BGCCacheItem*[cache_total_size];
+  cache = new GCCacheItem*[cache_total_size];
   for (i = 0; i < cache_total_size; ++i) {
-    cache[i] = new BGCCacheItem;
+    cache[i] = new GCCacheItem;
   }
 }
 
 
-BGCCache::~BGCCache(void) {
+GCCache::~GCCache(void) {
   std::for_each(contexts, contexts + context_count, PointerAssassin());
   std::for_each(cache, cache + cache_total_size, PointerAssassin());
   delete [] cache;
@@ -83,16 +85,16 @@ BGCCache::~BGCCache(void) {
 }
 
 
-BGCCacheContext *BGCCache::nextContext(unsigned int scr) {
-  Window hd = OBDisplay::screenInfo(scr)->getRootWindow();
+GCCacheContext *GCCache::nextContext(unsigned int scr) {
+  Window hd = display->screenInfo(scr)->rootWindow();
 
-  BGCCacheContext *c;
+  GCCacheContext *c;
 
   for (unsigned int i = 0; i < context_count; ++i) {
     c = contexts[i];
 
     if (! c->gc) {
-      c->gc = XCreateGC(OBDisplay::display, hd, 0, 0);
+      c->gc = XCreateGC(**display, hd, 0, 0);
       c->used = false;
       c->screen = scr;
     }
@@ -100,26 +102,26 @@ BGCCacheContext *BGCCache::nextContext(unsigned int scr) {
       return c;
   }
 
-  fprintf(stderr, "BGCCache: context fault!\n");
+  fprintf(stderr, "GCCache: context fault!\n");
   abort();
-  return (BGCCacheContext*) 0; // not reached
+  return (GCCacheContext*) 0; // not reached
 }
 
 
-void BGCCache::release(BGCCacheContext *ctx) {
+void GCCache::release(GCCacheContext *ctx) {
   ctx->used = false;
 }
 
 
-BGCCacheItem *BGCCache::find(const BColor &_color,
-                             const XFontStruct * const _font,
-                             int _function, int _subwindow, int _linewidth) {
+GCCacheItem *GCCache::find(const Color &_color,
+                           const XFontStruct * const _font,
+                           int _function, int _subwindow, int _linewidth) {
   const unsigned long pixel = _color.pixel();
   const unsigned int screen = _color.screen();
   const int key = _color.red() ^ _color.green() ^ _color.blue();
   int k = (key % cache_size) * cache_buckets;
   unsigned int i = 0; // loop variable
-  BGCCacheItem *c = cache[ k ], *prev = 0;
+  GCCacheItem *c = cache[ k ], *prev = 0;
 
   /*
     this will either loop cache_buckets times then return/abort or
@@ -144,7 +146,7 @@ BGCCacheItem *BGCCache::find(const BColor &_color,
       return c;
     }
     // cache fault!
-    fprintf(stderr, "BGCCache: cache fault, count: %d, screen: %d, item screen: %d\n", c->count, screen, c->ctx->screen);
+    fprintf(stderr, "GCCache: cache fault, count: %d, screen: %d, item screen: %d\n", c->count, screen, c->ctx->screen);
     abort();
   }
 
@@ -170,14 +172,14 @@ BGCCacheItem *BGCCache::find(const BColor &_color,
 }
 
 
-void BGCCache::release(BGCCacheItem *_item) {
+void GCCache::release(GCCacheItem *_item) {
   _item->count--;
 }
 
 
-void BGCCache::purge(void) {
+void GCCache::purge(void) {
   for (unsigned int i = 0; i < cache_total_size; ++i) {
-    BGCCacheItem *d = cache[ i ];
+    GCCacheItem *d = cache[ i ];
 
     if (d->ctx && d->count == 0) {
       release(d->ctx);
This page took 0.025461 seconds and 4 git commands to generate.