From c3a1c76b44bbc4dfe2cc13b298a2c4134b5f9a18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sat, 10 Nov 2012 19:25:54 +0100 Subject: [PATCH] get_default_icon_filename rewritten The function get_default_icon_filename(), now get_icon_filename(), was working in a bad way. Before this patch, the function always searched the default icon in the second search: - file_name = wDefaultGetIconFile(winstance, wclass, True); + file_name = wDefaultGetIconFile(winstance, wclass, False); For this reason, the argument default_icon didn't work. This patch change it. Now, if the default_icon is false, the function can return NULL, then other functions can do the correct work. For example, now wDefaultGetImage() doesn't need do nothing, because the default_icon is set to True. get_icon_filename() checks if the icon exists in the disk before returning it (except for default icon in get_default_image_path(scr). --- src/defaults.h | 4 ++-- src/dialog.c | 2 +- src/icon.c | 4 ++-- src/wdefaults.c | 33 +++++++++------------------------ 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/defaults.h b/src/defaults.h index 4104f842..e834c5a5 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -50,7 +50,7 @@ RImage * wDefaultGetImage(WScreen *scr, char *winstance, char *wclass, int max_s int wDefaultGetStartWorkspace(WScreen *scr, char *instance, char *class); void wDefaultChangeIcon(WScreen *scr, char *instance, char* class, char *file); RImage *get_default_image(WScreen *scr); -char *get_default_icon_filename(WScreen *scr, char *winstance, char *wclass, char *command, - Bool default_icon); +char *get_icon_filename(WScreen *scr, char *winstance, char *wclass, char *command, + Bool default_icon); RImage *get_rimage_from_file(WScreen *scr, char *file_name, int max_size); #endif /* WMDEFAULTS_H_ */ diff --git a/src/dialog.c b/src/dialog.c index 5ec3ec6b..69644958 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -1467,7 +1467,7 @@ static WMPixmap *getWindowMakerIconImage(WMScreen *scr) char *path = NULL; /* Get the Logo icon, without the default icon */ - path = get_default_icon_filename(NULL, "Logo", "WMPanel", NULL, False); + path = get_icon_filename(NULL, "Logo", "WMPanel", NULL, False); if (path) { RColor gray; diff --git a/src/icon.c b/src/icon.c index f82be538..c9875658 100644 --- a/src/icon.c +++ b/src/icon.c @@ -144,7 +144,7 @@ WIcon *icon_create_for_wwindow(WWindow *wwin) wGetIconName(dpy, wwin->client_win, &icon->icon_name); /* Get the application icon, default included */ - file = get_default_icon_filename(scr, wwin->wm_instance, wwin->wm_class, NULL, True); + file = get_icon_filename(scr, wwin->wm_instance, wwin->wm_class, NULL, True); if (file) { icon->file = wstrdup(file); icon->file_image = get_rimage_from_file(scr, icon->file, wPreferences.icon_size); @@ -169,7 +169,7 @@ WIcon *icon_create_for_dock(WScreen *scr, char *command, char *wm_instance, char icon = icon_create_core(scr, 0, 0); /* Search the icon using instance and class, without default icon */ - file = get_default_icon_filename(scr, wm_instance, wm_class, command, False); + file = get_icon_filename(scr, wm_instance, wm_class, command, False); if (file) { icon->file = wstrdup(file); icon->file_image = get_rimage_from_file(scr, icon->file, wPreferences.icon_size); diff --git a/src/wdefaults.c b/src/wdefaults.c index 532b19ec..a342369b 100644 --- a/src/wdefaults.c +++ b/src/wdefaults.c @@ -376,8 +376,8 @@ static WMPropList *get_generic_value(char *instance, char *class, } /* Get the file name of the image, using instance and class */ -char *get_default_icon_filename(WScreen *scr, char *winstance, char *wclass, char *command, - Bool default_icon) +char *get_icon_filename(WScreen *scr, char *winstance, char *wclass, char *command, + Bool default_icon) { char *file_name = NULL; char *file_path = NULL; @@ -389,13 +389,11 @@ char *get_default_icon_filename(WScreen *scr, char *winstance, char *wclass, cha if (file_name) file_path = FindImage(wPreferences.icon_path, file_name); - /* If the specific (or generic if default_icon is True) icon filename - * is not found, and command is specified, then include the .app icons - * and re-do the search, but now always including the default icon - * so the icon is found always. The .app is selected before default */ + /* If the specific icon filename is not found, and command is specified, + * then include the .app icons and re-do the search. */ if ((!file_name || !file_path ) && scr && command) { wApplicationExtractDirPackIcon(scr, command, winstance, wclass); - file_name = wDefaultGetIconFile(winstance, wclass, True); + file_name = wDefaultGetIconFile(winstance, wclass, False); } /* Get the full path for the image file */ @@ -403,21 +401,15 @@ char *get_default_icon_filename(WScreen *scr, char *winstance, char *wclass, cha file_path = FindImage(wPreferences.icon_path, file_name); if (!file_path) - wwarning(_("could not find icon file \"%s\""), file_name); + wwarning(_("icon \"%s\" doesn't exist, check your config files"), file_name); /* FIXME: Here, if file_path don't exists, then the icon is in the * "icon database" (WDWindowAttributes->dictionary), but the icon * is not en disk. Therefore, we should remove it from the icon - * database. - * OTOH, probably the correct message should be "could not find the - * icon file %s, please, check your configuration files", because - * the icons are loaded in the icon database from the configuration - * files - */ + * database. Is possible to do that using wDefaultChangeIcon() */ /* Don't wfree(file_name) here, because is a pointer to the icon - * dictionary (WDWindowAttributes->dictionary) value. - */ + * dictionary (WDWindowAttributes->dictionary) value. */ } if (!file_path && default_icon) @@ -482,14 +474,7 @@ RImage *wDefaultGetImage(WScreen *scr, char *winstance, char *wclass, int max_si char *file_name = NULL; /* Get the file name of the image, using instance and class */ - file_name = get_default_icon_filename(scr, winstance, wclass, NULL, True); - - /* If no filename, is because the winstance and wclass in the database - * returns a invalid icon (config file error), then should be removed FIXME! */ - if (!file_name) { - wwarning(_("icon \"%s\" doesn't exist, check your config files"), file_name); - file_name = get_default_image_path(scr); - } + file_name = get_icon_filename(scr, winstance, wclass, NULL, True); return get_rimage_from_file(scr, file_name, max_size); } -- 2.11.4.GIT