From: "Rodolfo García Peñas (kix)" <[email protected]>

This patch changes the behavior of wIconChangeImageFile.

Before apply this patch the behavior was:

The image (file_image) is set to NULL, then the function tried to find
a new image. If the new image was not found, the variable file_image contains
NULL when the function returns, and the return code was 1.

With this patch the image is changed only if a new image is found.
---
 src/icon.c |   32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/icon.c b/src/icon.c
index 0b95df2..f693e77 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -373,31 +373,39 @@ Bool wIconChangeImageFile(WIcon *icon, char *file)
 {
        WScreen *scr = icon->core->screen_ptr;
        char *path;
+       RImage *image = NULL;
        int error = 0;
 
+       /* If no new image, don't do nothing */
        if (!file)
                return True;
 
-       if (icon->file_image) {
-               RReleaseImage(icon->file_image);
-               icon->file_image = NULL;
-       }
-
+       /* Find the new image */
        path = FindImage(wPreferences.icon_path, file);
-       if (path) {
-               icon->file_image = get_rimage_from_file(scr, path, 
wPreferences.icon_size);
+       if (path)
+               image = get_rimage_from_file(scr, path, wPreferences.icon_size);
+       else
+               error = 1;
+
+       /* New image! */
+       if (!error && image) {
+               /* Remove the old one */
                if (icon->file_image) {
-                       icon->file = wstrdup(path);
-                       wIconUpdate(icon);
-               } else {
-                       error = 1;
+                       RReleaseImage(icon->file_image);
+                       icon->file_image = NULL;
                }
 
-               wfree(path);
+               /* Set the new image */
+               icon->file_image = image;
+               icon->file = wstrdup(path);
+               wIconUpdate(icon);
        } else {
                error = 1;
        }
 
+       if (path)
+               wfree(path);
+
        return !error;
 }
 
-- 
1.7.10.4


-- 
To unsubscribe, send mail to [email protected].

Reply via email to