A bit of refactoring
o9000 mrovi9000@gmail.com
1 files changed,
20 insertions(+),
23 deletions(-)
jump to
M
src/launcher/icon-theme-common.c
→
src/launcher/icon-theme-common.c
@@ -48,7 +48,7 @@ {
return parse_dektop_line(line, key, value); } -GSList *icon_locations = NULL; +static GSList *icon_locations = NULL; // Do not free the result. const GSList *get_icon_locations() {@@ -72,6 +72,21 @@
icon_locations = slist_remove_duplicates(icon_locations, g_str_equal, g_free); return icon_locations; +} + +static GSList *icon_extensions = NULL; +const GSList *get_icon_extensions() +{ + if (icon_extensions) + return icon_extensions; + + icon_extensions = g_slist_append(icon_extensions, ".png"); + icon_extensions = g_slist_append(icon_extensions, ".xpm"); +#ifdef HAVE_RSVG + icon_extensions = g_slist_append(icon_extensions, ".svg"); +#endif + icon_extensions = g_slist_append(icon_extensions, ""); + return icon_extensions; } IconTheme *make_theme(const char *name)@@ -564,27 +579,13 @@ if (result)
return result; const GSList *basenames = get_icon_locations(); - GSList *extensions = NULL; - extensions = g_slist_append(extensions, ".png"); - extensions = g_slist_append(extensions, ".xpm"); -#ifdef HAVE_RSVG - extensions = g_slist_append(extensions, ".svg"); -#endif - // if the icon name already contains one of the extensions (e.g. vlc.png instead of vlc) add a special entry - for (GSList *ext = extensions; ext; ext = g_slist_next(ext)) { - char *extension = (char *)ext->data; - if (strlen(icon_name) > strlen(extension) && - strcmp(extension, icon_name + strlen(icon_name) - strlen(extension)) == 0) { - extensions = g_slist_append(extensions, ""); - break; - } - } + const GSList *extensions = get_icon_extensions(); GSList *theme; // Best size match // Contrary to the freedesktop spec, we are not choosing the closest icon in size, but the next larger icon - // otherwise the quality is usually crap (for size 22, if you can choose 16 or 32, you're better with 32) + // otherwise the quality is worse when scaling up (for size 22, if you can choose 16 or 32, you're better with 32) // We do fallback to the closest size if we cannot find a larger or equal icon // These 3 variables are used for keeping the closest size match@@ -622,7 +623,7 @@ if (debug_icons)
fprintf(stderr, "tint2: Searching directory: %s\n", ((IconThemeDir *)dir->data)->name); const GSList *base; for (base = basenames; base; base = g_slist_next(base)) { - for (GSList *ext = extensions; ext; ext = g_slist_next(ext)) { + for (const GSList *ext = extensions; ext; ext = g_slist_next(ext)) { char *base_name = (char *)base->data; char *theme_name = ((IconTheme *)theme->data)->name; char *dir_name = ((IconThemeDir *)dir->data)->name;@@ -677,12 +678,10 @@ }
free(file_name); file_name = NULL; if (next_larger) { - g_slist_free(extensions); free(best_file_name); return next_larger; } if (best_file_name) { - g_slist_free(extensions); return best_file_name; }@@ -691,7 +690,7 @@ {
if (debug_icons) fprintf(stderr, "tint2: Searching unthemed icons\n"); for (const GSList *base = basenames; base; base = g_slist_next(base)) { - for (GSList *ext = extensions; ext; ext = g_slist_next(ext)) { + for (const GSList *ext = extensions; ext; ext = g_slist_next(ext)) { char *base_name = (char *)base->data; char *extension = (char *)ext->data; size_t file_name_size2 = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100;@@ -703,7 +702,6 @@ fprintf(stderr, "tint2: Checking %s\n", file_name);
if (g_file_test(file_name, G_FILE_TEST_EXISTS)) { if (debug_icons) fprintf(stderr, "tint2: Found %s\n", file_name); - g_slist_free(extensions); return file_name; } else { free(file_name);@@ -713,7 +711,6 @@ }
} } - g_slist_free(extensions); return NULL; }