A bit of refactoring
This commit is contained in:
@@ -48,7 +48,7 @@ int parse_theme_line(char *line, char **key, char **value)
|
|||||||
return parse_dektop_line(line, key, value);
|
return parse_dektop_line(line, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
GSList *icon_locations = NULL;
|
static GSList *icon_locations = NULL;
|
||||||
// Do not free the result.
|
// Do not free the result.
|
||||||
const GSList *get_icon_locations()
|
const GSList *get_icon_locations()
|
||||||
{
|
{
|
||||||
@@ -74,6 +74,21 @@ const GSList *get_icon_locations()
|
|||||||
return icon_locations;
|
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)
|
IconTheme *make_theme(const char *name)
|
||||||
{
|
{
|
||||||
IconTheme *theme = calloc(1, sizeof(IconTheme));
|
IconTheme *theme = calloc(1, sizeof(IconTheme));
|
||||||
@@ -564,27 +579,13 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
const GSList *basenames = get_icon_locations();
|
const GSList *basenames = get_icon_locations();
|
||||||
GSList *extensions = NULL;
|
const GSList *extensions = get_icon_extensions();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GSList *theme;
|
GSList *theme;
|
||||||
|
|
||||||
// Best size match
|
// Best size match
|
||||||
// Contrary to the freedesktop spec, we are not choosing the closest icon in size, but the next larger icon
|
// 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
|
// 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
|
// These 3 variables are used for keeping the closest size match
|
||||||
@@ -622,7 +623,7 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
|||||||
fprintf(stderr, "tint2: Searching directory: %s\n", ((IconThemeDir *)dir->data)->name);
|
fprintf(stderr, "tint2: Searching directory: %s\n", ((IconThemeDir *)dir->data)->name);
|
||||||
const GSList *base;
|
const GSList *base;
|
||||||
for (base = basenames; base; base = g_slist_next(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 *base_name = (char *)base->data;
|
||||||
char *theme_name = ((IconTheme *)theme->data)->name;
|
char *theme_name = ((IconTheme *)theme->data)->name;
|
||||||
char *dir_name = ((IconThemeDir *)dir->data)->name;
|
char *dir_name = ((IconThemeDir *)dir->data)->name;
|
||||||
@@ -677,12 +678,10 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
|||||||
free(file_name);
|
free(file_name);
|
||||||
file_name = NULL;
|
file_name = NULL;
|
||||||
if (next_larger) {
|
if (next_larger) {
|
||||||
g_slist_free(extensions);
|
|
||||||
free(best_file_name);
|
free(best_file_name);
|
||||||
return next_larger;
|
return next_larger;
|
||||||
}
|
}
|
||||||
if (best_file_name) {
|
if (best_file_name) {
|
||||||
g_slist_free(extensions);
|
|
||||||
return best_file_name;
|
return best_file_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,7 +690,7 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
|||||||
if (debug_icons)
|
if (debug_icons)
|
||||||
fprintf(stderr, "tint2: Searching unthemed icons\n");
|
fprintf(stderr, "tint2: Searching unthemed icons\n");
|
||||||
for (const GSList *base = basenames; base; base = g_slist_next(base)) {
|
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 *base_name = (char *)base->data;
|
||||||
char *extension = (char *)ext->data;
|
char *extension = (char *)ext->data;
|
||||||
size_t file_name_size2 = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100;
|
size_t file_name_size2 = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100;
|
||||||
@@ -703,7 +702,6 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
|||||||
if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
|
if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
|
||||||
if (debug_icons)
|
if (debug_icons)
|
||||||
fprintf(stderr, "tint2: Found %s\n", file_name);
|
fprintf(stderr, "tint2: Found %s\n", file_name);
|
||||||
g_slist_free(extensions);
|
|
||||||
return file_name;
|
return file_name;
|
||||||
} else {
|
} else {
|
||||||
free(file_name);
|
free(file_name);
|
||||||
@@ -713,7 +711,6 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free(extensions);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user