imlib2 fixed, i forgot when the window size changes we totally destroy the pixmap...
[monky] / src / imlib2.c
index 394da1f..0ffce8c 100644 (file)
@@ -1,10 +1,11 @@
 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
  *
  * Conky, a system monitor, based on torsmo
  *
  * Please see COPYING for details
  *
- * Copyright (c) 2005-2009 Brenden Matthews, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, et. al.
  * All rights reserved.
  *
  * This program is free software: you can redistribute it and/or modify
@@ -19,8 +20,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * vim: ts=4 sw=4 noet ai cindent syntax=c
- *
  */
 
 #include "config.h"
@@ -86,9 +85,15 @@ 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, Drawable 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: '<path to image> (-p x,y) (-s WxH) (-n) (-f interval)' (got '%s')", args);
+               NORM_ERR("Invalid args for $image.  Format is: '<path to image> (-p"
+                               "x,y) (-s WxH) (-n) (-f interval)' (got '%s')", args);
                free(cur);
                return;
        }
@@ -154,18 +169,21 @@ 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);
+       static int rep = 0;
 
        image = imlib_load_image(cur->name);
        if (!image) {
-               NORM_ERR("Unable to load image '%s'", cur->name);
+               if (!rep)
+                       NORM_ERR("Unable to load image '%s'", cur->name);
+               rep = 1;
                return;
        }
+       rep = 0;        /* reset so disappearing images are reported */
 
        DBGP("Drawing image '%s' at (%i,%i) scaled to %ix%i, "
             "caching interval set to %i (with -n opt %i)",
@@ -213,8 +231,8 @@ void cimlib_render(int x, int y, int width, int height)
        time_t now;
 
        if (!image_list_start) return; /* are we actually drawing anything? */
-
-       /* cheque if it's time to flush our cache */
+        fprintf(stderr, PACKAGE_NAME": cimlib_render start\n");
+       /* check 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) {
                int size = imlib_get_cache_size();
@@ -223,7 +241,6 @@ void cimlib_render(int x, int y, int width, int height)
                cimlib_cache_flush_last = now;
                DBGP("Flushing Imlib2 cache (%li)\n", now);
        }
-
        /* take all the little rectangles to redraw and merge them into
         * something sane for rendering */
        buffer = imlib_create_image(width, height);
@@ -234,16 +251,12 @@ void cimlib_render(int x, int y, int width, int height)
        imlib_context_set_blend(1);
        /* turn alpha channel on */
        imlib_image_set_has_alpha(1);
-
        cimlib_draw_all(&clip_x, &clip_y, &clip_x2, &clip_y2);
-
        /* set the buffer image as our current image */
        imlib_context_set_image(buffer);
-
        /* setup our clip rect */
        if (clip_x == INT_MAX) clip_x = 0;
        if (clip_y == INT_MAX) clip_y = 0;
-
        /* render the image at 0, 0 */
        imlib_render_image_part_on_drawable_at_size(clip_x, clip_y, clip_x2 - clip_x,
                        clip_y2 - clip_y, x + clip_x, y + clip_y, clip_x2 - clip_x,