Subject: No way to reload a cached image (fix)

From: Mikhael Goikhman <[email-masked]>
Date: Fri, 14 Jan 2000 22:47:35 +0200

If the decor picture is in the image cache, and you change this image
(editing or resymlinking) the new decor is created with the old cached
image (and there is no way to change it, even using RecaptureWindow).
You just can't switch decors using the same image names on fly.

Here is a simple patch. I want to apply it unless someone suggest another
fix to this problem.

P.S. There should be added a file size for ident, not only modif date.
And reloading images in FvwmButtons or menus is another story.

Regards,
Mikhael.
Index: libs/Picture.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/libs/Picture.c,v
retrieving revision 1.36
diff -u -r1.36 Picture.c
--- libs/Picture.c	2000/01/12 21:38:40	1.36
+++ libs/Picture.c	2000/01/14 20:03:09
@@ -53,6 +53,7 @@
 
 #include <X11/keysym.h>
 #include <sys/time.h>
+#include <sys/stat.h>
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -165,6 +166,30 @@
     return searchPath( pathlist, icon, ".gz", type );
 }
 
+PictureIdent getPictureIdent(Picture *p)
+{
+  static struct stat buf;
+
+  if (!p || !p->name || stat(p->name, &buf))
+    return 0;
+  return
+    buf.st_mtime;
+}
+
+void setPictureIdent(Picture *p)
+{
+  if (!p)
+    return;
+  p->ident = getPictureIdent(p);
+}
+
+int isPictureIdentChanged(Picture *p)
+{
+  if (!p)
+    return;
+  return
+    p->ident != getPictureIdent(p);
+}
 
 Picture *LoadPicture(Display *dpy, Window Root, char *path, int color_limit)
 {
@@ -180,6 +205,7 @@
   p->count = 1;
   p->name = path;
   p->next = NULL;
+  setPictureIdent(p);
 
 #ifdef XPM
   /* Try to load it as an X Pixmap first */
@@ -258,7 +284,8 @@
 	    if (*p1 != *p2)
 		break;
 
-	if(!*p1 && !*p2) /* We have found a picture with the wanted name */
+	/* If we have found a picture with the wanted name and ident */
+	if (!*p1 && !*p2 && !isPictureIdentChanged(p))
 	{
 	    p->count++; /* Put another weight on the picture */
 	    free(path);
Index: libs/Picture.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/libs/Picture.h,v
retrieving revision 1.12
diff -u -r1.12 Picture.h
--- libs/Picture.h	1999/10/03 19:23:43	1.12
+++ libs/Picture.h	2000/01/14 20:03:09
@@ -16,11 +16,14 @@
 #ifndef Picture_H
 #define Picture_H
 
+/* Don't waste too much memory on image identification */
+#define PictureIdent time_t
 
 typedef struct PictureThing
 {
     struct PictureThing *next;
     char *name;
+    PictureIdent ident;
     Pixmap picture;
     Pixmap mask;
     unsigned int depth;