Load fallback icon themes lazily to speed up tint2 startup

This commit is contained in:
o9000 2016-02-28 15:41:50 +01:00
parent df241dfd89
commit 1000cbf491
3 changed files with 40 additions and 24 deletions

View file

@ -316,6 +316,7 @@ void free_themes(IconThemeWrapper *themes)
free(theme); free(theme);
} }
g_slist_free(themes->themes_fallback); g_slist_free(themes->themes_fallback);
g_slist_free_full(themes->_queued, free);
free(themes); free(themes);
} }
@ -415,9 +416,18 @@ IconThemeWrapper *load_themes(const char *icon_theme_name)
fprintf(stderr, "Loading %s. Icon theme :", icon_theme_name); fprintf(stderr, "Loading %s. Icon theme :", icon_theme_name);
} }
GSList *queued = NULL; load_themes_helper(icon_theme_name, &wrapper->themes, &wrapper->_queued);
load_themes_helper(icon_theme_name, &wrapper->themes, &queued); load_themes_helper("hicolor", &wrapper->themes, &wrapper->_queued);
load_themes_helper("hicolor", &wrapper->themes, &queued);
return wrapper;
}
void load_fallbacks(IconThemeWrapper *wrapper)
{
if (wrapper->_fallback_loaded)
return;
fprintf(stderr, RED "Loading additional icon themes (this means your icon theme is incomplete)..." RESET "\n");
// Load wrapper->themes_fallback // Load wrapper->themes_fallback
const GSList *location; const GSList *location;
@ -429,7 +439,7 @@ IconThemeWrapper *load_themes(const char *icon_theme_name)
while ((name = g_dir_read_name(d))) { while ((name = g_dir_read_name(d))) {
gchar *file_name = g_build_filename(path, name, "index.theme", NULL); gchar *file_name = g_build_filename(path, name, "index.theme", NULL);
if (g_file_test(file_name, G_FILE_TEST_EXISTS) && !g_file_test(file_name, G_FILE_TEST_IS_DIR)) { if (g_file_test(file_name, G_FILE_TEST_EXISTS) && !g_file_test(file_name, G_FILE_TEST_IS_DIR)) {
load_themes_helper(name, &wrapper->themes_fallback, &queued); load_themes_helper(name, &wrapper->themes_fallback, &wrapper->_queued);
} }
g_free(file_name); g_free(file_name);
} }
@ -437,13 +447,7 @@ IconThemeWrapper *load_themes(const char *icon_theme_name)
} }
} }
// Free the queued list wrapper->_fallback_loaded = TRUE;
GSList *l;
for (l = queued; l; l = l->next)
free(l->data);
g_slist_free(queued);
return wrapper;
} }
int directory_matches_size(IconThemeDir *dir, int size) int directory_matches_size(IconThemeDir *dir, int size)
@ -647,21 +651,30 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
return NULL; return NULL;
} }
char *get_icon_path(IconThemeWrapper *theme, const char *icon_name, int size) char *get_icon_path(IconThemeWrapper *wrapper, const char *icon_name, int size)
{ {
if (!theme) if (!wrapper)
return NULL; return NULL;
if (!icon_name || strlen(icon_name) == 0)
return NULL;
icon_name = icon_name ? icon_name : DEFAULT_ICON; icon_name = icon_name ? icon_name : DEFAULT_ICON;
char *path = get_icon_path_helper(theme->themes, icon_name, size); char *path = get_icon_path_helper(wrapper->themes, icon_name, size);
if (!path) { if (path)
path = get_icon_path_helper(theme->themes_fallback, icon_name, size); return path;
}
if (!path) { fprintf(stderr, YELLOW "Icon not found in default theme: %s" RESET "\n", icon_name);
fprintf(stderr, "Could not find icon %s\n", icon_name); load_fallbacks(wrapper);
path = get_icon_path_helper(theme->themes, DEFAULT_ICON, size);
} path = get_icon_path_helper(wrapper->themes_fallback, icon_name, size);
if (!path) { if (path)
path = get_icon_path_helper(theme->themes_fallback, DEFAULT_ICON, size); return path;
}
fprintf(stderr, RED "Could not find icon %s, using default." RESET "\n", icon_name);
path = get_icon_path_helper(wrapper->themes, DEFAULT_ICON, size);
if (path)
return path;
path = get_icon_path_helper(wrapper->themes_fallback, DEFAULT_ICON, size);
return path; return path;
} }

View file

@ -13,6 +13,8 @@ typedef struct IconThemeWrapper {
GSList *themes; GSList *themes;
// List of IconTheme* // List of IconTheme*
GSList *themes_fallback; GSList *themes_fallback;
GSList *_queued;
gboolean _fallback_loaded;
} IconThemeWrapper; } IconThemeWrapper;
typedef struct IconTheme { typedef struct IconTheme {

View file

@ -176,3 +176,4 @@ tint2.desktop
tint2.files tint2.files
tint2.includes tint2.includes
tint2.svg tint2.svg
src/tint2conf/po/ru.po