From ea131baceb10b7f032da725e194c4f4b48586739 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 15 Jul 2011 20:35:09 +0200 Subject: Attach a modifiedSig handler to the session.cacheMax resource --- src/FbTk/ImageControl.cc | 12 ++++++++---- src/FbTk/ImageControl.hh | 3 ++- src/Screen.cc | 4 +++- src/fluxbox.hh | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc index 9eaec31..a745cf8 100644 --- a/src/FbTk/ImageControl.cc +++ b/src/FbTk/ImageControl.cc @@ -177,7 +177,7 @@ struct ImageControl::Cache { ImageControl::ImageControl(int screen_num, int cpc, unsigned int cache_timeout, unsigned long cmax): m_colors_per_channel(cpc), - m_screen_num(screen_num) { + m_screen_num(screen_num), m_cache_max(cmax) { Display *disp = FbTk::App::instance()->display(); @@ -185,8 +185,6 @@ ImageControl::ImageControl(int screen_num, m_visual = DefaultVisual(disp, screen_num); m_colormap = DefaultColormap(disp, screen_num); - cache_max = cmax; - RefCount > clean_cache(new SimpleCommand(*this, &ImageControl::cleanCache)); m_timer.setCommand(clean_cache); setCacheTimeout(cache_timeout); @@ -226,6 +224,12 @@ void ImageControl::setCacheTimeout(unsigned int cache_timeout) { m_timer.stop(); } +void ImageControl::setCacheMax(unsigned long cache_max) { + m_cache_max = cache_max; + if (cache.size() > m_cache_max) + cleanCache(); +} + Pixmap ImageControl::searchCache(unsigned int width, unsigned int height, const Texture &text, FbTk::Orientation orient) const { @@ -326,7 +330,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height, cache.push_back(tmp); - if (cache.size() > cache_max) + if (cache.size() > m_cache_max) cleanCache(); return pixmap; diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh index 1795bbf..983b319 100644 --- a/src/FbTk/ImageControl.hh +++ b/src/FbTk/ImageControl.hh @@ -46,6 +46,7 @@ public: virtual ~ImageControl(); void setCacheTimeout(unsigned int cache_timeout); + void setCacheMax(unsigned long cache_max); int depth() const { return m_screen_depth; } int colorsPerChannel() const { return m_colors_per_channel; } @@ -112,7 +113,7 @@ private: typedef std::list CacheList; mutable CacheList cache; - unsigned long cache_max; + unsigned long m_cache_max; }; } // end namespace FbTk diff --git a/src/Screen.cc b/src/Screen.cc index 701e38a..82a4939 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -387,11 +387,13 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, // setup image cache engine m_image_control.reset(new FbTk::ImageControl(scrn, fluxbox->colorsPerChannel(), - *fluxbox->getCacheLifeResource(), fluxbox->getCacheMax())); + *fluxbox->getCacheLifeResource(), *fluxbox->getCacheMaxResource())); imageControl().installRootColormap(); root_colormap_installed = true; m_tracker.join(fluxbox->getCacheLifeResource().modifiedSig(), MemFun(imageControl(), &FbTk::ImageControl::setCacheTimeout)); + m_tracker.join(fluxbox->getCacheMaxResource().modifiedSig(), + MemFun(imageControl(), &FbTk::ImageControl::setCacheMax)); m_root_theme.reset(new RootTheme(imageControl())); m_root_theme->reconfigTheme(); diff --git a/src/fluxbox.hh b/src/fluxbox.hh index 92d6daf..20b25fb 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -130,7 +130,7 @@ public: time_t getAutoRaiseDelay() const { return *m_rc_auto_raise_delay; } FbTk::UIntResource &getCacheLifeResource() { return m_rc_cache_life; } - unsigned int getCacheMax() const { return *m_rc_cache_max; } + FbTk::UIntResource &getCacheMaxResource() { return m_rc_cache_max; } void maskWindowEvents(Window w, FluxboxWindow *bw) -- cgit v0.11.2