Merge branch 'icon-loading-performance-deferred-load-2'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Closes #124
authored by Daniel Eklöf · committed by Daniel Eklöf · parents 64e9738, 51c973d · Browse files · 9 files·+406 added−199 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+406 added−199 removed
- other:+406 added−199 removed
Provenance
- Commit
a32a026- Tree
e89413e- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent 1
64e9738- Parent 2
51c973d
9 files changed+406 added−199 removed
modified:application.c+9 added-4 removed
246 unmodified lines247 case ICON_NONE:248 break;249 250 case ICON_PNG:251+ if (app->icon.png != NULL) {252 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)252- free(pixman_image_get_data(app->icon.png));253- pixman_image_unref(app->icon.png);253+ free(pixman_image_get_data(app->icon.png));254+ pixman_image_unref(app->icon.png);255 #endif256+ }257 break;258 259 case ICON_SVG:260+ if (app->icon.svg != NULL) {261 #if defined(FUZZEL_ENABLE_SVG_LIBRSVG)259- g_object_unref(app->icon.svg);262+ g_object_unref(app->icon.svg);263 #elif defined(FUZZEL_ENABLE_SVG_NANOSVG)261- nsvgDelete(app->icon.svg);264+ nsvgDelete(app->icon.svg);265 #endif266+ }267 break;268 }269 270 tll_foreach(app->icon.rasterized, it) {1 unmodified line272 free(pixman_image_get_data(rast->pix));273 pixman_image_unref(rast->pix);274 tll_remove(app->icon.rasterized, it);275 }276+ free(app->icon.path);277 278 fcft_text_run_destroy(app->shaped);279 }280 12 unmodified linesmodified:application.h+5 added
24 unmodified lines25 typedef tll(struct rasterized) rasterized_list_t;26 27 struct icon {28 char *name;29+ char *path;30 enum icon_type type;31 union {32 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)33 pixman_image_t *png;34+#else35+ void *png;36 #endif37 #if defined(FUZZEL_ENABLE_SVG_LIBRSVG)38 RsvgHandle *svg;39 #elif defined(FUZZEL_ENABLE_SVG_NANOSVG)40 NSVGimage *svg;41+#else42+ void *svg;43 #endif44 };45 46 /* List of cached rasterizations (used with SVGs) */33 unmodified linesmodified:CHANGELOG.md+2 added
40 unmodified lines41 and can be used by setting the `-Dsvg-backend=librsvg` meson option.42 * It is no longer necessary to close stdin when using fuzzel in dmenu43 mode, as long as `--no-run-if-empty` is **not** being used44 (https://codeberg.org/dnkl/fuzzel/issues/106).45+* Improved performance of initial rendering of icons46+ (https://codeberg.org/dnkl/fuzzel/issues/124).47 48 49 ### Deprecated50 ### Removed306 unmodified linesmodified:icon.c+324 added-179 removed
4 unmodified lines5 #include <string.h>6 #include <stdbool.h>7 #include <assert.h>8 #include <unistd.h>9+#include <limits.h>10 11 #include <sys/stat.h>12 #include <fcntl.h>13 18 unmodified lines32 33 typedef tll(char *) theme_names_t;34 35 static bool35-dir_is_usable(const char *path, const char *context, const char *type)36+dir_is_usable(const char *path, const char *context)37 {38 if (path == NULL || context == NULL) {39 return false;40 }20 unmodified lines61 int size = -1;62 int min_size = -1;63 int max_size = -1;64 int scale = 1;65+ int threshold = 2;66 char *context = NULL;65- char *type = NULL;67+ enum icon_dir_type type = ICON_DIR_THRESHOLD;68 69 while (true) {70 char *line = NULL;71 size_t sz = 0;20 unmodified lines92 }93 94 if (line[0] == '[' && line[len - 1] == ']') {95 94- if (dir_is_usable(section, context, type)) {95- struct icon_dir dir = {96- .path = section,97- .size = size,98- .min_size = min_size >= 0 ? min_size : size,99- .max_size = max_size >= 0 ? max_size : size,100- .scale = scale,101- .scalable = strcasecmp(type, "scalable") == 0,102- };103- tll_push_back(theme->dirs, dir);104- } else105- free(section);96+ tll_foreach(theme->dirs, it) {97+ struct icon_dir *d = &it->item;98 99+ if (section == NULL || strcmp(d->path, section) != 0)100+ continue;101+102+ if (!dir_is_usable(section, context))103+ break;104+105+ d->size = size;106+ d->min_size = min_size >= 0 ? min_size : size;107+ d->max_size = max_size >= 0 ? max_size : size;108+ d->scale = scale;109+ d->threshold = threshold;110+ d->type = type;111+ }112+113+ free(section);114 free(context);108- free(type);115 116 size = min_size = max_size = -1;117 scale = 1;118 section = NULL;119 context = NULL;114- type = NULL;120+ type = ICON_DIR_THRESHOLD;121+ threshold = 2;122 123 section = malloc(len - 2 + 1);124 memcpy(section, &line[1], len - 2);125 section[len - 2] = '\0';14 unmodified lines140 tll_push_back(*themes_to_load, strdup(theme_name));141 }142 }143 137- if (strcasecmp(key, "size") == 0)144+ if (strcasecmp(key, "directories") == 0) {145+ char *save = NULL;146+ for (const char *d = strtok_r(value, ",", &save);147+ d != NULL;148+ d = strtok_r(NULL, ",", &save))149+ {150+ struct icon_dir dir = {.path = strdup(d)};151+ tll_push_back(theme->dirs, dir);152+ }153+ }154+155+ else if (strcasecmp(key, "size") == 0)156 sscanf(value, "%d", &size);157 158 else if (strcasecmp(key, "minsize") == 0)159 sscanf(value, "%d", &min_size);6 unmodified lines166 167 else if (strcasecmp(key, "context") == 0)168 context = strdup(value);169 152- else if (strcasecmp(key, "type") == 0)153- type = strdup(value);170+ else if (strcasecmp(key, "threshold") == 0)171+ sscanf(value, "%d", &threshold);172 173+ else if (strcasecmp(key, "type") == 0) {174+ if (strcasecmp(value, "fixed") == 0)175+ type = ICON_DIR_FIXED;176+ else if (strcasecmp(value, "scalable") == 0)177+ type = ICON_DIR_SCALABLE;178+ else if (strcasecmp(value, "threshold") == 0)179+ type = ICON_DIR_THRESHOLD;180+ else {181+ LOG_WARN(182+ "ignoring unrecognized icon theme directory type: %s",183+ value);184+ }185+ }186+187 free(line);188 }189 158- if (dir_is_usable(section, context, type)) {159- struct icon_dir dir = {160- .path = section,161- .size = size,162- .min_size = min_size >= 0 ? min_size : size,163- .max_size = max_size >= 0 ? max_size : size,164- .scale = scale165- };166- tll_push_back(theme->dirs, dir);167- } else168- free(section);190+ tll_foreach(theme->dirs, it) {191+ struct icon_dir *d = &it->item;192 193+ if (section == NULL || strcmp(d->path, section) != 0)194+ continue;195+196+ if (!dir_is_usable(section, context))197+ break;198+199+ d->size = size;200+ d->min_size = min_size >= 0 ? min_size : size;201+ d->max_size = max_size >= 0 ? max_size : size;202+ d->scale = scale;203+ d->threshold = threshold;204+ d->type = type;205+ }206+207+ tll_foreach(theme->dirs, it) {208+ if (it->item.size == 0) {209+ free(it->item.path);210+ tll_remove(theme->dirs, it);211+ }212+ }213+214+ free(section);215 free(context);171- free(type);216 }217 218 static bool219 load_theme_in(const char *dir, struct icon_theme *theme,220 theme_names_t *themes_to_load)221 {178- int theme_dir_fd = -1;179- int index_fd = -1;180- FILE *index = NULL;181- bool ret = false;222+ char path[PATH_MAX];223+ snprintf(path, sizeof(path), "%s/index.theme", dir);224 183- theme_dir_fd = open(dir, O_RDONLY);184- if (theme_dir_fd == -1) {185- //LOG_ERRNO("%s: failed to open", dir);186- goto out;187- }225+ FILE *index = fopen(path, "r");226+ if (index == NULL)227+ return false;228 189- index_fd = openat(theme_dir_fd, "index.theme", O_RDONLY);190- if (index_fd == -1) {191- //LOG_ERRNO("%s/index.theme: failed to open", dir);192- goto out;193- }194-195- index = fdopen(index_fd, "r");196- assert(index != NULL);197-229 parse_theme(index, theme, themes_to_load);199-200- ret = true;201-202- out:203- if (index != NULL)204- fclose(index);205- if (index_fd != -1)206- close(index_fd);207- if (theme_dir_fd != -1)208- close(theme_dir_fd);209- return ret;230+ fclose(index);231+ return true;232 }233 234 icon_theme_list_t235 icon_load_theme(const char *name)31 unmodified lines267 continue;268 }269 270 tll_foreach(dirs, dir_it) {249- char path[strlen(dir_it->item) + 1 +271+ char path[strlen(dir_it->item.path) + 1 +272 strlen("icons") + 1 +273 strlen(theme_name) + 1];252- sprintf(path, "%s/icons/%s", dir_it->item, theme_name);274+ sprintf(path, "%s/icons/%s", dir_it->item.path, theme_name);275 276 struct icon_theme theme = {0};277 if (load_theme_in(path, &theme, &themes_to_load)) {278 theme.name = strdup(theme_name);27 unmodified lines306 tll_remove(themes, it);307 }308 }309 288-static bool289-icon_null(struct icon *icon)290-{291- icon->type = ICON_NONE;292- return true;293-}294-310 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)311 static bool312 icon_from_png_libpng(struct icon *icon, const char *file_name)313 {6 unmodified lines320 return true;321 }322 #endif323 309-static bool324+bool325 icon_from_png(struct icon *icon, const char *name)326 {327 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)328 return icon_from_png_libpng(icon, name);35 unmodified lines364 return true;365 }366 #endif367 353-static bool368+bool369 icon_from_svg(struct icon *icon, const char *name)370 {371 #if defined(FUZZEL_ENABLE_SVG_LIBRSVG)372 return icon_from_svg_librsvg(icon, name);3 unmodified lines376 return false;377 #endif378 }379 380+static bool381+svg(struct icon *icon, const char *path)382+{383+ icon->path = strdup(path);384+ icon->type = ICON_SVG;385+ icon->svg = NULL;386+ return true;387+}388+389+static bool390+png(struct icon *icon, const char *path)391+{392+ icon->path = strdup(path);393+ icon->type = ICON_PNG;394+ icon->png = NULL;395+ return true;396+}397+398 static void399 icon_reset(struct icon *icon)400 {401+ free(icon->path);402+ icon->path = NULL;403+404 switch (icon->type) {405 case ICON_NONE:406 break;407 21 unmodified lines429 free(pixman_image_get_data(rast->pix));430 pixman_image_unref(rast->pix);431 tll_remove(icon->rasterized, it);432 }397- 433+434 icon->type = ICON_NONE;435 }436 437 static bool402-reload_icon(struct icon *icon, int icon_size, icon_theme_list_t themes)438+lookup_icons(const icon_theme_list_t *themes, int icon_size,439+ struct application_list *applications,440+ const xdg_data_dirs_t *xdg_dirs)441 {404- if (icon->name == NULL)405- return true;442+ struct icon_data {443+ const char *name;444+ struct application *app;445 407- const char *name = icon->name;408- icon_reset(icon);446+ char *file_name;447+ size_t file_name_len;448 410- if (name == NULL)411- return icon_null(icon);449+ struct {450+ int diff;451+ const struct xdg_data_dir *xdg_dir;452+ const struct icon_theme *theme;453+ const struct icon_dir *icon_dir;454+ enum icon_type type;455+ } min_diff;456+ };457 413- if (name[0] == '/') {414- if (icon_from_svg(icon, name)) {415- LOG_DBG("%s: absolute path SVG", name);416- return true;417- }458+ tll(struct icon_data) icons = tll_init();459 419- if (icon_from_png(icon, name)) {420- LOG_DBG("%s: absolute path PNG", name);421- return true;422- }460+ for (size_t i = 0; i < applications->count; i++) {461+ struct application *app = &applications->v[i];462+ icon_reset(&app->icon);463 424- return icon_null(icon);425- }464+ if (app->icon.name == NULL)465+ continue;466 427- LOG_DBG("looking for %s (wanted size: %d)", name, icon_size);467+ if (app->icon.name[0] == '/') {468+ if (svg(&app->icon, app->icon.name))469+ LOG_DBG("%s: absolute path SVG", app->icon.name);470+ else if (png(&app->icon, app->icon.name))471+ LOG_DBG("%s: abslute path PNG", app->icon.name);472+ } else {473+ size_t file_name_len = strlen(app->icon.name) + 4;474+ char *file_name = malloc(file_name_len + 1);475+ strcpy(file_name, app->icon.name);476+ strcat(file_name, ".xxx");477 429- xdg_data_dirs_t xdg_dirs = xdg_data_dirs();478+ struct icon_data data = {479+ .name = app->icon.name,480+ .app = app,481+ .file_name = file_name,482+ .file_name_len = file_name_len,483+ .min_diff = {.diff = INT_MAX},484+ };485+ tll_push_back(icons, data);486+ }487+ }488 489+ /* For details, see490+ * https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup */491+431- tll_foreach(themes, theme_it) {492+ tll_foreach(*themes, theme_it) {493 const struct icon_theme *theme = &theme_it->item;433- int min_diff = 10000;494 495+ /* Fallback icon to use if there aren’t any exact matches */496 /* Assume sorted */436- for (size_t i = 0; i < 4; i++) {437- tll_foreach(theme->dirs, icon_dir_it) {438- const struct icon_dir *icon_dir = &icon_dir_it->item;497+ tll_foreach(theme->dirs, icon_dir_it) {498+ const struct icon_dir *icon_dir = &icon_dir_it->item;499 440- tll_foreach(xdg_dirs, xdg_dir_it) {441- const char *xdg_dir = xdg_dir_it->item;500+ char theme_relative_path[501+ 5 + 1 + /* “icons” */502+ strlen(theme->name) + 1 +503+ strlen(icon_dir->path) + 1];504 443- const int size = icon_dir->size * icon_dir->scale;444- const int min_size = icon_dir->min_size * icon_dir->scale;445- const int max_size = icon_dir->max_size * icon_dir->scale;446- const bool scalable = icon_dir->scalable;505+ sprintf(theme_relative_path, "icons/%s/%s",506+ theme->name, icon_dir->path);507 448- const size_t len = strlen(xdg_dir) + 1 +449- strlen("icons") + 1 +450- strlen(theme->name) + 1 +451- strlen(icon_dir->path) + 1 +452- strlen(name) + strlen(".png") + 1;508+ tll_foreach(*xdg_dirs, xdg_dir_it) {509+ const struct xdg_data_dir *xdg_dir = &xdg_dir_it->item;510 454- /* Check if a png/svg file exists at all */455- char *full_path = malloc(len);456- sprintf(full_path, "%s/icons/%s/%s/%s.png",457- xdg_dir, theme->name, icon_dir->path, name);511+ const int scale = icon_dir->scale;512+ const int size = icon_dir->size * scale;513+ const int min_size = icon_dir->min_size * scale;514+ const int max_size = icon_dir->max_size * scale;515+ const int threshold = icon_dir->threshold * scale;516+ const enum icon_dir_type type = icon_dir->type;517 459- if (access(full_path, O_RDONLY) == -1) {460- /* Also check for svg variant */461- full_path[len - 4] = 's';462- full_path[len - 3] = 'v';463- full_path[len - 2] = 'g';464- if (access(full_path, O_RDONLY) == -1) {465- free(full_path);518+ bool is_exact_match = false;;519+ int diff = INT_MAX;520+521+ /* See if this directory is usable for the requested icon size */522+ switch (type) {523+ case ICON_DIR_FIXED:524+ is_exact_match = size == icon_size;525+ diff = abs(size - icon_size);526+ break;527+528+ case ICON_DIR_THRESHOLD:529+ is_exact_match =530+ (size - threshold) <= icon_size &&531+ (size + threshold) >= icon_size;532+ diff = icon_size < (size - threshold)533+ ? (size - threshold) - icon_size534+ : icon_size - (size + threshold);535+ break;536+537+ case ICON_DIR_SCALABLE:538+ is_exact_match =539+ min_size <= icon_size &&540+ max_size >= icon_size;541+ diff = icon_size < min_size542+ ? min_size - icon_size543+ : icon_size - max_size;544+ break;545+ }546+547+ int dir_fd = openat(548+ xdg_dir->fd, theme_relative_path, O_RDONLY | O_DIRECTORY);549+ if (dir_fd < 0)550+ continue;551+552+ tll_foreach(icons, icon_it) {553+ struct icon_data *icon = &icon_it->item;554+555+ if (!is_exact_match && icon->min_diff.diff < diff)556+ continue;557+558+ size_t len = icon->file_name_len;559+ char *path = icon->file_name;560+ path[len - 4] = '.';561+ path[len - 3] = 'p';562+ path[len - 2] = 'n';563+ path[len - 1] = 'g';564+565+ if (faccessat(dir_fd, path, R_OK, 0) < 0) {566+ path[len - 3] = 's';567+ path[len - 2] = 'v';568+ path[len - 1] = 'g';569+ if (faccessat(dir_fd, path, R_OK, 0) < 0)570 continue;467- }571 }572 470- const int diff = scalable ? 0 : abs(size - icon_size);471- if (i == 0 && diff != 0) {472- /* Looking for *exactly* our wanted size */473- if (diff < min_diff)474- min_diff = diff;475- free(full_path);573+ if (!is_exact_match) {574+ assert(diff < icon->min_diff.diff);575+ icon->min_diff.diff = diff;576+ icon->min_diff.xdg_dir = xdg_dir;577+ icon->min_diff.theme = theme;578+ icon->min_diff.icon_dir = icon_dir;579+ icon->min_diff.type = path[len - 3] == 's'580+ ? ICON_SVG : ICON_PNG;581 continue;477- } else if (i == 1 && diff != min_diff) {478- /* Try the one which matches most closely */479- free(full_path);480- continue;481- } else if (i == 2 && (icon_size < min_size ||482- icon_size > max_size))483- {484- /* Find one whose scalable range we're in */485- free(full_path);486- continue;487- } else {488- /* Use anyone available */582 }583 491- if (icon_from_svg(icon, full_path)) {492- LOG_DBG("%s: %s scalable", name, full_path);493- free(full_path);494- goto success;495- }584+ char *full_path = malloc(585+ strlen(xdg_dir->path) + 1 +586+ 5 + 1 + /* “icons” */587+ strlen(theme->name) + 1 +588+ strlen(icon_dir->path) + 1 +589+ len + 1);590 497- if (icon_from_png(icon, full_path)) {498- if (scalable)499- LOG_DBG("%s: %s: scalable", name, full_path);500- else if (i == 0)501- LOG_DBG("%s: %s: exact match", name, full_path);502- else if (i == 1)503- LOG_DBG("%s: %s: diff = %d", name, full_path, diff);504- else if (i == 2)505- LOG_DBG("%s: %s: range %d-%d",506- name, full_path, min_size, max_size);507- else508- LOG_DBG("%s: %s: nothing else matched", name, full_path);591+ sprintf(full_path, "%s/icons/%s/%s/%s",592+ xdg_dir->path, theme->name, icon_dir->path, path);593 510- free(full_path);511- goto success;594+ if ((path[len - 3] == 's' &&595+ svg(&icon->app->icon, full_path)) ||596+ (path[len - 3] == 'p' &&597+ png(&icon->app->icon, full_path)))598+ {599+ LOG_DBG("%s: %s", icon->name, full_path);600+ free(icon->file_name);601+ tll_remove(icons, icon_it);602 }513-514- free(full_path);603 }604+605+ close(dir_fd);606 }607 }518- }608 520- tll_foreach(xdg_dirs, it) {521- char path[strlen(it->item) + 1 +522- strlen("pixmaps") + 1 +523- strlen(name) + strlen(".svg") + 1];609+ /* Try loading fallbacks for those icons we didn’t find an610+ * exact match */611+ tll_foreach(icons, icon_it) {612+ struct icon_data *icon = &icon_it->item;613 525- /* Try SVG variant first */526- sprintf(path, "%s/pixmaps/%s.svg", it->item, name);527- if (icon_from_svg(icon, path))528- goto success;614+ if (icon->min_diff.type == ICON_NONE) {615+ assert(icon->min_diff.xdg_dir == NULL);616+ continue;617+ }618 530- /* No SVG, look for PNG instead */531- sprintf(path, "%s/pixmaps/%s.png", it->item, name);532- if (icon_from_png(icon, path))533- goto success;619+ size_t path_len =620+ strlen(icon->min_diff.xdg_dir->path) + 1 +621+ 5 + 1 + /* “icons” */622+ strlen(icon->min_diff.theme->name) + 1 +623+ strlen(icon->min_diff.icon_dir->path) + 1 +624+ strlen(icon->name) + 4;625+626+ char full_path[path_len + 1];627+ sprintf(full_path, "%s/icons/%s/%s/%s.%s",628+ icon->min_diff.xdg_dir->path,629+ icon->min_diff.theme->name,630+ icon->min_diff.icon_dir->path,631+ icon->name,632+ icon->min_diff.type == ICON_SVG ? "svg" : "png");633+634+ if ((icon->min_diff.type == ICON_SVG &&635+ svg(&icon->app->icon, full_path)) ||636+ (icon->min_diff.type == ICON_PNG &&637+ png(&icon->app->icon, full_path)))638+ {639+ LOG_DBG("%s: %s (fallback)", icon->name, full_path);640+ free(icon->file_name);641+ tll_remove(icons, icon_it);642+ } else {643+ /* Reset diff data, before checking the parent theme(s) */644+ icon->min_diff.diff = INT_MAX;645+ icon->min_diff.xdg_dir = NULL;646+ icon->min_diff.theme = NULL;647+ icon->min_diff.icon_dir = NULL;648+ icon->min_diff.type = ICON_NONE;649+ }650+ }651 }652 536- icon_null(icon);653+ /* Finally, look in XDG_DATA_DIRS/pixmaps */654+ tll_foreach(icons, icon_it) {655+ const struct icon_data *icon = &icon_it->item;656 538-success:539- xdg_data_dirs_destroy(xdg_dirs);657+ tll_foreach(*xdg_dirs, it) {658+ const size_t len =659+ strlen(it->item.path) + 1 +660+ strlen("pixmaps") + 1 +661+ strlen(icon->name) + strlen(".svg");662+ char path[len + 1];663+664+ /* Try SVG variant first */665+ sprintf(path, "%s/pixmaps/%s.svg", it->item.path, icon->name);666+ if (svg(&icon->app->icon, path)) {667+ LOG_DBG("%s: %s (pixmaps)", icon->name, path);668+ break;669+ }670+671+ /* No SVG, look for PNG instead */672+ path[len - 3] = 'p';673+ path[len - 2] = 'n';674+ path[len - 1] = 'g';675+ if (png(&icon->app->icon, path)) {676+ LOG_DBG("%s: %s (pixmaps)", icon->name, path);677+ break;678+ }679+ }680+681+ free(icon->file_name);682+ tll_remove(icons, icon_it);683+ }684+685 return true;686 }687 688 bool544-icon_reload_application_icons(icon_theme_list_t themes, int icon_size,689+icon_lookup_application_icons(icon_theme_list_t themes, int icon_size,690 struct application_list *applications)691 {547- for (size_t i = 0; i < applications->count; i++)548- if (!reload_icon(&applications->v[i].icon, icon_size, themes))549- return false;692+ xdg_data_dirs_t xdg_dirs = xdg_data_dirs();693+ lookup_icons(&themes, icon_size, applications, &xdg_dirs);694+ xdg_data_dirs_destroy(xdg_dirs);695 696 return true;697 }modified:icon.h+12 added-2 removed
3 unmodified lines4 5 #include "application.h"6 #include "tllist.h"7 8+enum icon_dir_type {9+ ICON_DIR_FIXED,10+ ICON_DIR_SCALABLE,11+ ICON_DIR_THRESHOLD,12+};13+14 struct icon_dir {15 char *path; /* Relative to theme's base path */16 int size;17 int min_size;18 int max_size;19 int scale;14- bool scalable;20+ int threshold;21+ enum icon_dir_type type;22 };23 24 struct icon_theme {25 char *name;4 unmodified lines30 31 icon_theme_list_t icon_load_theme(const char *name);32 void icon_themes_destroy(icon_theme_list_t themes);33 27-bool icon_reload_application_icons(34+bool icon_lookup_application_icons(35 icon_theme_list_t themes, int icon_size,36 struct application_list *applications);37+38+bool icon_from_png(struct icon *icon, const char *name);39+bool icon_from_svg(struct icon *icon, const char *name);modified:main.c+2 added-2 removed
268 unmodified lines269 mtx_lock(ctx->icon_lock);270 {271 ctx->icon_size = font->height;272 if (ctx->options.icons_enabled) {273- icon_reload_application_icons(273+ icon_lookup_application_icons(274 *ctx->themes, ctx->icon_size, ctx->apps);275 }276 }277 mtx_unlock(ctx->icon_lock);123 unmodified lines401 mtx_lock(ctx->icon_lock);402 {403 *ctx->themes = icon_themes;404 if (ctx->icon_size > 0) {405- icon_reload_application_icons(405+ icon_lookup_application_icons(406 *ctx->themes, ctx->icon_size, apps);407 }408 }409 mtx_unlock(ctx->icon_lock);727 unmodified linesmodified:render.c+11 added
12 unmodified lines13 #define LOG_MODULE "render"14 #define LOG_ENABLE_DBG 015 #include "log.h"16 #include "char32.h"17+#include "icon.h"18 #include "stride.h"19 #include "wayland.h"20 21 #define min(x, y) ((x) < (y) ? (x) : (y))410 unmodified lines432 render_svg(struct icon *icon, int x, int y, int size, struct buffer *buf)433 {434 assert(icon->type == ICON_SVG);435 436+ if (icon->svg == NULL) {437+ if (!icon_from_svg(icon, icon->path))438+ return;439+ }440+441 #if defined(FUZZEL_ENABLE_SVG_LIBRSVG)442 render_svg_librsvg(icon, x, y, size, buf);443 #elif defined(FUZZEL_ENABLE_SVG_NANOSVG)444 render_svg_nanosvg(icon, x, y, size, buf);73 unmodified lines518 render_png(struct icon *icon, int x, int y, int size, struct buffer *buf)519 {520 assert(icon->type == ICON_PNG);521 522+ if (icon->png == NULL) {523+ if (!icon_from_png(icon, icon->path))524+ return;525+ }526+527 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)528 render_png_libpng(icon, x, y, size, buf);529 #endif530 }235 unmodified linesmodified:xdg.c+35 added-10 removed
408 unmodified lines409 application_llist_t apps = tll_init();410 411 xdg_data_dirs_t dirs = xdg_data_dirs();412 tll_foreach(dirs, it) {413- char path[strlen(it->item) + 1 + strlen("applications") + 1];414- sprintf(path, "%s/applications", it->item);413+ char path[strlen(it->item.path) + 1 + strlen("applications") + 1];414+ sprintf(path, "%s/applications", it->item.path);415 416 int fd = open(path, O_RDONLY);417 if (fd != -1) {418 scan_dir(fd, terminal, include_actions, &apps, NULL);75 unmodified lines494 {495 xdg_data_dirs_t ret = tll_init();496 497 const char *xdg_data_home = getenv("XDG_DATA_HOME");498- if (xdg_data_home != NULL)499- tll_push_back(ret, strdup(xdg_data_home));500- else {498+ if (xdg_data_home != NULL && xdg_data_home[0] != '\0') {499+ int fd = open(xdg_data_home, O_RDONLY | O_DIRECTORY);500+ if (fd >= 0) {501+ struct xdg_data_dir d = {.fd = fd, .path = strdup(xdg_data_home)};502+ tll_push_back(ret, d);503+ }504+ } else {505 static const char *const local = ".local/share";506 const struct passwd *pw = getpwuid(getuid());507 508 char *path = malloc(strlen(pw->pw_dir) + 1 + strlen(local) + 1);509 sprintf(path, "%s/%s", pw->pw_dir, local);510+511+ int fd = open(path, O_RDONLY | O_DIRECTORY);512+ if (fd >= 0) {513+ struct xdg_data_dir d = {.fd = fd, .path = path};506- tll_push_back(ret, path);514+ tll_push_back(ret, d);515+ } else516+ free(path);517 }518 519 const char *_xdg_data_dirs = getenv("XDG_DATA_DIRS");520 5 unmodified lines526 for (const char *tok = strtok_r(copy, ":", &ctx);527 tok != NULL;528 tok = strtok_r(NULL, ":", &ctx))529 {530+ int fd = open(tok, O_RDONLY | O_DIRECTORY);531+ if (fd >= 0) {532+ struct xdg_data_dir d = {.fd = fd, .path = strdup(tok)};520- tll_push_back(ret, strdup(tok));533+ tll_push_back(ret, d);534+ }535 }536 537 free(copy);538 } else {525- tll_push_back(ret, strdup("/usr/local/share"));526- tll_push_back(ret, strdup("/usr/share"));539+ int fd1 = open("/usr/local/share", O_RDONLY | O_DIRECTORY);540+ int fd2 = open("/usr/share", O_RDONLY | O_DIRECTORY);541+542+ if (fd1 >= 0) {543+ struct xdg_data_dir d = {.fd = fd1, .path = strdup("/usr/local/share")};544+ tll_push_back(ret, d);545+ }546+547+ if (fd2 >= 0) {548+ struct xdg_data_dir d = {.fd = fd2, .path = strdup("/usr/share")};549+ tll_push_back(ret, d);;550+ }551 }552 553 return ret;554 }1 unmodified line556 void557 xdg_data_dirs_destroy(xdg_data_dirs_t dirs)558 {559 tll_foreach(dirs, it) {560+ close(it->item.fd);536- free(it->item);561+ free(it->item.path);562 tll_remove(dirs, it);563 }564 }565 12 unmodified linesmodified:xdg.h+6 added-2 removed
2 unmodified lines3 #include "application.h"4 #include "icon.h"5 #include "tllist.h"6 7-typedef tll(char *) xdg_data_dirs_t;8-//typedef tll(struct application) application_list_t;7+struct xdg_data_dir {8+ char *path;9+ int fd;10+};11 12+typedef tll(struct xdg_data_dir) xdg_data_dirs_t;13+14 xdg_data_dirs_t xdg_data_dirs(void);15 void xdg_data_dirs_destroy(xdg_data_dirs_t dirs);16 17 const char *xdg_cache_dir(void);4 unmodified lines