Skip to content
Myr

icon: in application mode (not dmenu), filter out non-application icon theme dirs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Use the 'context' field defined for each icon theme directory, and ignore all directories that are *not* for 'applications'. This is strictly speaking not according to the specification, which says that context should only be used for sorting/grouping. But, e.g. hicolor has so many directories, that there's a noticeable startup delay when there are many .desktop files that need to resolve icons. For many themes, this is not an issue, as they typically have a single 'scalable' directory. But if you're either using 'hicolor' explicitly, or you have lots of .desktop files with icons that don't exist in the primary icon theme, it becomes a performance issue. Note: we used to *always* filter on context. This was removed in 294ceb69391fcc16b6dfdd6d722c303a31f979adon, without any reference to a specific issue. It was probably done to better adhere to the specification. As such, I don't think there will be any issues reverting it. But, for now, only filter on context in application mode, not dmenu mode (since we don't know what the context there is). Related to #553

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 1ea01b1 · Browse files · 4 files+56 added−31 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+56 added−31 removed

  • other:+56 added−31 removed

4 files+56 added−31 removed

modified:CHANGELOG.md+5 added
52 unmodified lines
53 of displayed entries.54* wayland-protocols >= 1.41 is now required.55* pixman >= 0.46.0 is now required.56* fcft >= 3.3.1 is now required.57* In application mode (not dmenu), fuzzel now ignores icon theme58 directories whose `Context` field is not `Application` or59 `Apps`. This is for performance reasons ([#553][553])6061[553]: https://codeberg.org/dnkl/fuzzel/issues/553626364### Deprecated65### Removed66### Fixed67
924 unmodified lines
modified:icon.c+49 added-29 removed
32 unmodified lines
33#include "xsnprintf.h"3435typedef tll(char *) theme_names_t;3637static bool38dir_context_is_allowed(const char *context)39{40 static const char *const allowed_contexts[] = {"applications", "apps"};4142 if (context == NULL)43 return NULL;4445 for (size_t i = 0; i < sizeof(allowed_contexts) / sizeof(allowed_contexts[0]); i++) {46 if (strcasecmp(context, allowed_contexts[i]) == 0)47 return true;48 }4950 return false;51}5253static void38parse_theme(FILE *index, struct icon_theme *theme, theme_names_t *themes_to_load)54parse_theme(FILE *index, struct icon_theme *theme, bool filter_context,55 theme_names_t *themes_to_load)56{57 char *section = NULL;58 int size = -1;59 int min_size = -1;
28 unmodified lines
88 continue;89 }9091 if (line[0] == '[' && line[len - 1] == ']') {92 if (dir_context_is_allowed(context)) {93 tll_foreach(theme->dirs, it) {94 struct icon_dir *d = &it->item;9576 tll_foreach(theme->dirs, it) {77 struct icon_dir *d = &it->item;96 if (section == NULL || strcmp(d->path, section) != 0)97 continue;9879 if (section == NULL || strcmp(d->path, section) != 0)80 continue;8182 d->size = size;83 d->min_size = min_size >= 0 ? min_size : size;84 d->max_size = max_size >= 0 ? max_size : size;85 d->scale = scale;86 d->threshold = threshold;87 d->type = type;99 d->size = size;100 d->min_size = min_size >= 0 ? min_size : size;101 d->max_size = max_size >= 0 ? max_size : size;102 d->scale = scale;103 d->threshold = threshold;104 d->type = type;105 }106 }107108 free(section);109 free(context);
71 unmodified lines
181182 free(line);183 }184185 if (dir_context_is_allowed(context)) {167 tll_foreach(theme->dirs, it) {168 struct icon_dir *d = &it->item;186 tll_foreach(theme->dirs, it) {187 struct icon_dir *d = &it->item;188170 if (section == NULL || strcmp(d->path, section) != 0)171 continue;189 if (section == NULL || strcmp(d->path, section) != 0)190 continue;191173 d->size = size;174 d->min_size = min_size >= 0 ? min_size : size;175 d->max_size = max_size >= 0 ? max_size : size;176 d->scale = scale;177 d->threshold = threshold;178 d->type = type;192 d->size = size;193 d->min_size = min_size >= 0 ? min_size : size;194 d->max_size = max_size >= 0 ? max_size : size;195 d->scale = scale;196 d->threshold = threshold;197 d->type = type;198 }199 }200201 tll_foreach(theme->dirs, it) {202 if (it->item.size == 0) {
7 unmodified lines
210}211212static bool213load_theme_in(const char *dir, struct icon_theme *theme,194 theme_names_t *themes_to_load)214 bool filter_context, theme_names_t *themes_to_load)215{216 char path[PATH_MAX];217 xsnprintf(path, sizeof(path), "%s/index.theme", dir);218219 FILE *index = fopen(path, "re");220 if (index == NULL)221 return false;222203 parse_theme(index, theme, themes_to_load);223 parse_theme(index, theme, filter_context, themes_to_load);224 fclose(index);225 return true;226}227
9 unmodified lines
237}238239static void240discover_and_load_theme(const char *theme_name, xdg_data_dirs_t dirs,221 theme_names_t *themes_to_load,241 theme_names_t *themes_to_load, bool filter_context,242 icon_theme_list_t *themes)243{244 tll_foreach(dirs, dir_it) {245 char path[strlen(dir_it->item.path) + 1 +
1 unmodified line
247 strlen(theme_name) + 1];248 sprintf(path, "%s/icons/%s", dir_it->item.path, theme_name);249250 struct icon_theme theme = {0};231 if (load_theme_in(path, &theme, themes_to_load)) {251 if (load_theme_in(path, &theme, filter_context, themes_to_load)) {252 theme.name = xstrdup(theme_name);253 tll_push_back(*themes, theme);254 }255 }
40 unmodified lines
296 return dirs;297}298299icon_theme_list_t280icon_load_theme(const char *name)300icon_load_theme(const char *name, bool filter_context)301{302 /* List of themes; first item is the primary theme, subsequent303 * items are inherited items (i.e. fallback themes) */304 icon_theme_list_t themes = tll_init();
18 unmodified lines
323 free(theme_name);324 continue;325 }326307 discover_and_load_theme(theme_name, dirs, &themes_to_load, &themes);327 discover_and_load_theme(theme_name, dirs, &themes_to_load, filter_context, &themes);328 free(theme_name);329 }330331 /*
9 unmodified lines
341 /*342 * hicolor has no dependency, thus the themes_to_load here is343 * assumed to stay empty and will be disregarded.344 */325 discover_and_load_theme("hicolor", dirs, &themes_to_load, &themes);345 discover_and_load_theme("hicolor", dirs, &themes_to_load, filter_context, &themes);346 }347348 xdg_data_dirs_destroy(dirs);349 return themes;
482 unmodified lines
modified:icon.h+1 added-1 removed
26 unmodified lines
27};2829typedef tll(struct icon_theme) icon_theme_list_t;3031icon_theme_list_t icon_load_theme(const char *name);31icon_theme_list_t icon_load_theme(const char *name, bool filter_context);32void icon_themes_destroy(icon_theme_list_t themes);3334bool icon_lookup_application_icons(35 icon_theme_list_t themes, int icon_size,
4 unmodified lines
modified:main.c+1 added-1 removed
593 unmodified lines
594 return r;595596 if (icons_enabled) {597 gettimeofday(&ctx->timing.icons_theme.start, NULL);598 icon_theme_list_t icon_themes = icon_load_theme(icon_theme);598 icon_theme_list_t icon_themes = icon_load_theme(icon_theme, !dmenu_enabled);599 if (tll_length(icon_themes) > 0)600 LOG_INFO("theme: %s", tll_front(icon_themes).name);601 else602 LOG_WARN("%s: icon theme not found", icon_theme);
1553 unmodified lines