From 51ddee12ddad1cb3b00d8a29516c10869a8ac9e4 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Mon, 3 Aug 2009 12:39:44 -0600 Subject: [PATCH] Fix imlib2 context. --- src/conky.c | 3 +++ src/imlib2.c | 24 +++++++++++++++++++----- src/imlib2.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/conky.c b/src/conky.c index 86bdbb9a..da733326 100644 --- a/src/conky.c +++ b/src/conky.c @@ -7787,6 +7787,9 @@ void clean_up(void *memtofree1, void* memtofree2) llua_shutdown_hook(); llua_close(); #endif /* HAVE_LUA */ +#ifdef IMLIB2 + cimlib_deinit(); +#endif /* IMLIB2 */ if (specials) { for (i = 0; i < special_count; i++) { diff --git a/src/imlib2.c b/src/imlib2.c index 394da1fc..fd72790a 100644 --- a/src/imlib2.c +++ b/src/imlib2.c @@ -86,9 +86,14 @@ void cimlib_cleanup(void) image_list_start = image_list_end = NULL; } -void cimlib_init(Display *disp, Window drawable, Visual *visual, Colormap colourmap) +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); @@ -101,6 +106,15 @@ void cimlib_init(Display *disp, Window drawable, Visual *visual, Colormap colour 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; @@ -110,7 +124,8 @@ void cimlib_add_image(const char *args) memset(cur, 0, sizeof(struct image_list_s)); if (!sscanf(args, "%1023s", cur->name)) { - NORM_ERR("Invalid args for $image. Format is: ' (-p x,y) (-s WxH) (-n) (-f interval)' (got '%s')", args); + NORM_ERR("Invalid args for $image. Format is: ' (-p" + "x,y) (-s WxH) (-n) (-f interval)' (got '%s')", args); free(cur); return; } @@ -154,9 +169,8 @@ void cimlib_add_image(const char *args) } } -static void -cimlib_draw_image(struct image_list_s *cur, int *clip_x, - int *clip_y, int *clip_x2, int *clip_y2) +static void cimlib_draw_image(struct image_list_s *cur, int *clip_x, int + *clip_y, int *clip_x2, int *clip_y2) { int w, h; time_t now = time(NULL); diff --git a/src/imlib2.h b/src/imlib2.h index f36aac87..747571c6 100644 --- a/src/imlib2.h +++ b/src/imlib2.h @@ -30,6 +30,7 @@ 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);