mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-23 22:52:34 +01:00
wIconChangeImageFile change image only if found
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.
This commit is contained in:
committed by
Carlos R. Mafra
parent
3d0223ded4
commit
5728b6436d
32
src/icon.c
32
src/icon.c
@@ -373,31 +373,39 @@ Bool wIconChangeImageFile(WIcon *icon, char *file)
|
|||||||
{
|
{
|
||||||
WScreen *scr = icon->core->screen_ptr;
|
WScreen *scr = icon->core->screen_ptr;
|
||||||
char *path;
|
char *path;
|
||||||
|
RImage *image = NULL;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
|
/* If no new image, don't do nothing */
|
||||||
if (!file)
|
if (!file)
|
||||||
return True;
|
return True;
|
||||||
|
|
||||||
if (icon->file_image) {
|
/* Find the new image */
|
||||||
RReleaseImage(icon->file_image);
|
|
||||||
icon->file_image = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
path = FindImage(wPreferences.icon_path, file);
|
path = FindImage(wPreferences.icon_path, file);
|
||||||
if (path) {
|
if (path)
|
||||||
icon->file_image = get_rimage_from_file(scr, path, wPreferences.icon_size);
|
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) {
|
if (icon->file_image) {
|
||||||
icon->file = wstrdup(path);
|
RReleaseImage(icon->file_image);
|
||||||
wIconUpdate(icon);
|
icon->file_image = NULL;
|
||||||
} else {
|
|
||||||
error = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(path);
|
/* Set the new image */
|
||||||
|
icon->file_image = image;
|
||||||
|
icon->file = wstrdup(path);
|
||||||
|
wIconUpdate(icon);
|
||||||
} else {
|
} else {
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path)
|
||||||
|
wfree(path);
|
||||||
|
|
||||||
return !error;
|
return !error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user