From: "Rodolfo García Peñas (kix)" <k...@kix.es> This patch removes the function get_rimage_from_file. The code of this function is moved to the functions where is called.
I removed the function because the code inside make things dup, like if variables are NULL, warning messages,... Function get_default_image call twice wIconValidateIconSize(), now only one. --- src/defaults.h | 1 - src/icon.c | 16 ++++++++++++++-- src/wdefaults.c | 40 ++++++++++++++-------------------------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/defaults.h b/src/defaults.h index ace6b96..c1de48d 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -53,7 +53,6 @@ char *get_icon_filename(const char *winstance, const char *wclass, const char *c int wDefaultGetStartWorkspace(WScreen *scr, const char *instance, const char *class); void wDefaultChangeIcon(WScreen *scr, const char *instance, const char* class, const char *file); -RImage *get_rimage_from_file(WScreen *scr, const char *file_name, int max_size); void wDefaultPurgeInfo(WScreen *scr, const char *instance, const char *class); diff --git a/src/icon.c b/src/icon.c index fcdf663..0939dbe 100644 --- a/src/icon.c +++ b/src/icon.c @@ -368,8 +368,13 @@ Bool wIconChangeImageFile(WIcon *icon, const char *file) if (!path) return False; - image = get_rimage_from_file(scr, path, wPreferences.icon_size); + image = RLoadImage(scr->rcontext, path, 0); + image = wIconValidateIconSize(image, wPreferences.icon_size); + if (!image) { + wwarning(_("error loading image file \"%s\": %s"), path, + RMessageForError(RErrorCode)); + wfree(path); return False; } @@ -899,11 +904,18 @@ static void miniwindowMouseDown(WObjDescriptor * desc, XEvent * event) void set_icon_image_from_database(WIcon *icon, const char *wm_instance, const char *wm_class, const char *command) { char *file = NULL; + RImage *image = NULL; file = get_icon_filename(wm_instance, wm_class, command, False); if (file) { icon->file = wstrdup(file); - icon->file_image = get_rimage_from_file(icon->core->screen_ptr, icon->file, wPreferences.icon_size); + image = RLoadImage(icon->core->screen_ptr->rcontext, icon->file, 0); + image = wIconValidateIconSize(image, wPreferences.icon_size); + icon->file_image = image; + if (!image) + wwarning(_("error loading image file \"%s\": %s"), icon->file, + RMessageForError(RErrorCode)); + wfree(file); } } diff --git a/src/wdefaults.c b/src/wdefaults.c index 3378790..8650972 100644 --- a/src/wdefaults.c +++ b/src/wdefaults.c @@ -417,24 +417,6 @@ char *get_icon_filename(const char *winstance, const char *wclass, const char *c return file_path; } -/* This function returns the image picture for the file_name file */ -RImage *get_rimage_from_file(WScreen *scr, const char *file_name, int max_size) -{ - RImage *image = NULL; - - if (!file_name) - return NULL; - - image = RLoadImage(scr->rcontext, file_name, 0); - if (!image) - wwarning(_("error loading image file \"%s\": %s"), file_name, - RMessageForError(RErrorCode)); - - image = wIconValidateIconSize(image, max_size); - - return image; -} - /* This function returns the default icon's full path * If the path for an icon is not found, returns NULL */ char *get_default_image_path(void) @@ -461,25 +443,31 @@ RImage *get_default_image(WScreen *scr) return NULL; /* Get the default icon */ - image = get_rimage_from_file(scr, path, wPreferences.icon_size); + image = RLoadImage(scr->rcontext, path, 0); + image = wIconValidateIconSize(image, wPreferences.icon_size); if (!image) wwarning(_("could not find default icon \"%s\""), path); - /* Resize the icon to the wPreferences.icon_size size - * usually this function will return early, because size is right */ - image = wIconValidateIconSize(image, wPreferences.icon_size); - return image; } RImage *get_icon_image(WScreen *scr, const char *winstance, const char *wclass, int max_size) { - char *file_name = NULL; + RImage *image = NULL; + char *path = NULL; /* Get the file name of the image, using instance and class */ - file_name = get_icon_filename(winstance, wclass, NULL, True); + path = get_icon_filename(winstance, wclass, NULL, True); + if (!path) + return NULL; + + image = RLoadImage(scr->rcontext, path, 0); + image = wIconValidateIconSize(image, max_size); + if (!image) + wwarning(_("error loading image file \"%s\": %s"), path, + RMessageForError(RErrorCode)); - return get_rimage_from_file(scr, file_name, max_size); + return image; } int wDefaultGetStartWorkspace(WScreen *scr, const char *instance, const char *class) -- 1.7.10.4 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.