mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 17:47:09 +00:00
Make imlib_cache_{size,flush_interval} lua settings
This commit is contained in:
parent
ebd8a6d9fa
commit
eedb5241f8
18
src/conky.cc
18
src/conky.cc
@ -2568,10 +2568,6 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2)
|
||||
llua_shutdown_hook();
|
||||
llua_close();
|
||||
#endif /* BUILD_LUA */
|
||||
#ifdef BUILD_IMLIB2
|
||||
if (out_to_x.get(*state))
|
||||
cimlib_deinit();
|
||||
#endif /* BUILD_IMLIB2 */
|
||||
#if defined BUILD_WEATHER_XOAP || defined BUILD_RSS
|
||||
xmlCleanupParser();
|
||||
#endif
|
||||
@ -2820,20 +2816,6 @@ char load_config_file(const char *f)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* BUILD_X11 */
|
||||
#ifdef BUILD_X11
|
||||
#ifdef BUILD_IMLIB2
|
||||
CONF("imlib_cache_size") {
|
||||
if (value) {
|
||||
cimlib_set_cache_size(atoi(value));
|
||||
}
|
||||
}
|
||||
CONF("imlib_cache_flush_interval") {
|
||||
if (value) {
|
||||
cimlib_set_cache_flush_interval(atoi(value));
|
||||
}
|
||||
}
|
||||
#endif /* BUILD_IMLIB2 */
|
||||
#endif /* BUILD_X11 */
|
||||
CONF("update_interval_on_battery") {
|
||||
if (value) {
|
||||
|
@ -35,6 +35,8 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "x11.h"
|
||||
|
||||
struct image_list_s {
|
||||
char name[1024];
|
||||
Imlib_Image image;
|
||||
@ -52,26 +54,51 @@ Imlib_Updates updates, current_update;
|
||||
/* our virtual framebuffer image we draw into */
|
||||
Imlib_Image buffer, image;
|
||||
|
||||
static int cache_size_set = 0;
|
||||
namespace {
|
||||
Imlib_Context context;
|
||||
|
||||
/* flush the image cache ever X seconds */
|
||||
static int cimlib_cache_flush_interval = 0;
|
||||
static int cimlib_cache_flush_last = 0;
|
||||
conky::range_config_setting<unsigned int> imlib_cache_flush_interval(
|
||||
"imlib_cache_flush_interval", 0,
|
||||
std::numeric_limits<unsigned int>::max(), 0, true
|
||||
);
|
||||
|
||||
#define DEFAULT_IMLIB2_CACHE_SIZE 4096 * 1024 /* default cache size for loaded images */
|
||||
|
||||
void cimlib_set_cache_size(long size)
|
||||
{
|
||||
imlib_set_cache_size(size);
|
||||
cache_size_set = 1;
|
||||
int cimlib_cache_flush_last = 0;
|
||||
}
|
||||
|
||||
void cimlib_set_cache_flush_interval(long interval)
|
||||
void imlib_cache_size_setting::lua_setter(lua::state &l, bool init)
|
||||
{
|
||||
if (interval >= 0) {
|
||||
cimlib_cache_flush_interval = interval;
|
||||
} else {
|
||||
NORM_ERR("Imlib2: flush interval should be >= 0");
|
||||
lua::stack_sentry s(l, -2);
|
||||
|
||||
Base::lua_setter(l, init);
|
||||
|
||||
if(init && out_to_x.get(l)) {
|
||||
image_list_start = image_list_end = NULL;
|
||||
context = imlib_context_new();
|
||||
imlib_context_push(context);
|
||||
imlib_set_cache_size(do_convert(l, -1).first);
|
||||
/* set the maximum number of colors to allocate for 8bpp and less to 256 */
|
||||
imlib_set_color_usage(256);
|
||||
/* dither for depths < 24bpp */
|
||||
imlib_context_set_dither(1);
|
||||
/* set the display , visual, colormap and drawable we are using */
|
||||
imlib_context_set_display(display);
|
||||
imlib_context_set_visual(window.visual);
|
||||
imlib_context_set_colormap(window.colourmap);
|
||||
imlib_context_set_drawable(window.drawable);
|
||||
}
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
void imlib_cache_size_setting::cleanup(lua::state &l)
|
||||
{
|
||||
lua::stack_sentry s(l, -1);
|
||||
|
||||
if(out_to_x.get(l)) {
|
||||
cimlib_cleanup();
|
||||
imlib_context_disconnect_display();
|
||||
imlib_context_pop();
|
||||
imlib_context_free(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,35 +113,6 @@ void cimlib_cleanup(void)
|
||||
image_list_start = image_list_end = NULL;
|
||||
}
|
||||
|
||||
Imlib_Context context;
|
||||
|
||||
void cimlib_init(Display *disp, Window drawable, Visual *visual, Colormap
|
||||
colourmap)
|
||||
{
|
||||
image_list_start = image_list_end = NULL;
|
||||
context = imlib_context_new();
|
||||
imlib_context_push(context);
|
||||
if (!cache_size_set) cimlib_set_cache_size(DEFAULT_IMLIB2_CACHE_SIZE);
|
||||
/* set the maximum number of colors to allocate for 8bpp and less to 256 */
|
||||
imlib_set_color_usage(256);
|
||||
/* dither for depths < 24bpp */
|
||||
imlib_context_set_dither(1);
|
||||
/* set the display , visual, colormap and drawable we are using */
|
||||
imlib_context_set_display(disp);
|
||||
imlib_context_set_visual(visual);
|
||||
imlib_context_set_colormap(colourmap);
|
||||
imlib_context_set_drawable(drawable);
|
||||
}
|
||||
|
||||
void cimlib_deinit(void)
|
||||
{
|
||||
cimlib_cleanup();
|
||||
cache_size_set = 0;
|
||||
imlib_context_disconnect_display();
|
||||
imlib_context_pop();
|
||||
imlib_context_free(context);
|
||||
}
|
||||
|
||||
void cimlib_add_image(const char *args)
|
||||
{
|
||||
struct image_list_s *cur = NULL;
|
||||
@ -236,7 +234,8 @@ void cimlib_render(int x, int y, int width, int height)
|
||||
|
||||
/* cheque if it's time to flush our cache */
|
||||
now = time(NULL);
|
||||
if (cimlib_cache_flush_interval && now - cimlib_cache_flush_interval > cimlib_cache_flush_last) {
|
||||
if (imlib_cache_flush_interval.get(*state) &&
|
||||
now - imlib_cache_flush_interval.get(*state) > cimlib_cache_flush_last) {
|
||||
int size = imlib_get_cache_size();
|
||||
imlib_set_cache_size(0);
|
||||
imlib_set_cache_size(size);
|
||||
|
16
src/imlib2.h
16
src/imlib2.h
@ -30,11 +30,23 @@
|
||||
void cimlib_add_image(const char *name);
|
||||
void cimlib_set_cache_size(long size);
|
||||
void cimlib_set_cache_flush_interval(long interval);
|
||||
void cimlib_init(Display *display, Window drawable, Visual *visual, Colormap colourmap);
|
||||
void cimlib_deinit(void);
|
||||
void cimlib_render(int x, int y, int width, int height);
|
||||
void cimlib_cleanup(void);
|
||||
|
||||
void print_image_callback(struct text_object *, char *, int);
|
||||
|
||||
class imlib_cache_size_setting: public conky::range_config_setting<unsigned long> {
|
||||
typedef conky::range_config_setting<unsigned long> Base;
|
||||
|
||||
protected:
|
||||
virtual void lua_setter(lua::state &l, bool init);
|
||||
virtual void cleanup(lua::state &l);
|
||||
|
||||
public:
|
||||
imlib_cache_size_setting()
|
||||
: Base("imlib_cache_size", 0,
|
||||
std::numeric_limits<unsigned long>::max(), 4096*1024, true)
|
||||
{}
|
||||
};
|
||||
|
||||
#endif /* _CONKY_IMBLI2_H_ */
|
||||
|
12
src/x11.cc
12
src/x11.cc
@ -144,9 +144,6 @@ namespace priv {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef BUILD_IMLIB2 // FIXME: move this somewhere else
|
||||
cimlib_init(display, window.drawable, window.visual, window.colourmap);
|
||||
#endif /* BUILD_IMLIB2 */
|
||||
XFlush(display);
|
||||
return true;
|
||||
}
|
||||
@ -256,7 +253,7 @@ namespace {
|
||||
* The order of these settings cannot be completely arbitrary. Some of them depend on others, and
|
||||
* the setters are called in the order in which they are defined. The order should be:
|
||||
* display_name -> out_to_x -> everything colour related
|
||||
* -> border_*, own_window_*, etc -> own_window -> double_buffer
|
||||
* -> border_*, own_window_*, etc -> own_window -> double_buffer -> imlib_cache_size
|
||||
*/
|
||||
|
||||
conky::simple_config_setting<alignment> text_alignment("alignment", NONE, false);
|
||||
@ -315,6 +312,13 @@ priv::own_window_setting own_window;
|
||||
priv::use_xdbe_setting use_xdbe;
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_IMLIB2
|
||||
/*
|
||||
* the only reason this is not in imlib2.cc is so that we can be sure it's setter executes after
|
||||
* use_xdbe
|
||||
*/
|
||||
imlib_cache_size_setting imlib_cache_size;
|
||||
#endif
|
||||
/******************** </SETTINGS> ************************/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user