Skip to content
Myr

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

9 files+406 added−199 removed

modified:application.c+9 added-4 removed
246 unmodified lines
247 case ICON_NONE:248 break;249250 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;258259 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 }269270 tll_foreach(app->icon.rasterized, it) {
1 unmodified line
272 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);277278 fcft_text_run_destroy(app->shaped);279 }280
12 unmodified lines
modified:application.h+5 added
24 unmodified lines
25typedef tll(struct rasterized) rasterized_list_t;2627struct 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 };4546 /* List of cached rasterizations (used with SVGs) */
33 unmodified lines
modified:CHANGELOG.md+2 added
40 unmodified lines
41 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).474849### Deprecated50### Removed
306 unmodified lines
modified:icon.c+324 added-179 removed
4 unmodified lines
5#include <string.h>6#include <stdbool.h>7#include <assert.h>8#include <unistd.h>9#include <limits.h>1011#include <sys/stat.h>12#include <fcntl.h>13
18 unmodified lines
3233typedef tll(char *) theme_names_t;3435static bool35dir_is_usable(const char *path, const char *context, const char *type)36dir_is_usable(const char *path, const char *context)37{38 if (path == NULL || context == NULL) {39 return false;40 }
20 unmodified lines
61 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;6869 while (true) {70 char *line = NULL;71 size_t sz = 0;
20 unmodified lines
92 }9394 if (line[0] == '[' && line[len - 1] == ']') {9594 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;9899 if (section == NULL || strcmp(d->path, section) != 0)100 continue;101102 if (!dir_is_usable(section, context))103 break;104105 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 }112113 free(section);114 free(context);108 free(type);115116 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;122123 section = malloc(len - 2 + 1);124 memcpy(section, &line[1], len - 2);125 section[len - 2] = '\0';
14 unmodified lines
140 tll_push_back(*themes_to_load, strdup(theme_name));141 }142 }143137 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 }154155 else if (strcasecmp(key, "size") == 0)156 sscanf(value, "%d", &size);157158 else if (strcasecmp(key, "minsize") == 0)159 sscanf(value, "%d", &min_size);
6 unmodified lines
166167 else if (strcasecmp(key, "context") == 0)168 context = strdup(value);169152 else if (strcasecmp(key, "type") == 0)153 type = strdup(value);170 else if (strcasecmp(key, "threshold") == 0)171 sscanf(value, "%d", &threshold);172173 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 }186187 free(line);188 }189158 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;192193 if (section == NULL || strcmp(d->path, section) != 0)194 continue;195196 if (!dir_is_usable(section, context))197 break;198199 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 }206207 tll_foreach(theme->dirs, it) {208 if (it->item.size == 0) {209 free(it->item.path);210 tll_remove(theme->dirs, it);211 }212 }213214 free(section);215 free(context);171 free(type);216}217218static bool219load_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);224183 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;228189 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 }194195 index = fdopen(index_fd, "r");196 assert(index != NULL);197229 parse_theme(index, theme, themes_to_load);199200 ret = true;201202 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}233234icon_theme_list_t235icon_load_theme(const char *name)
31 unmodified lines
267 continue;268 }269270 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);275276 struct icon_theme theme = {0};277 if (load_theme_in(path, &theme, &themes_to_load)) {278 theme.name = strdup(theme_name);
27 unmodified lines
306 tll_remove(themes, it);307 }308}309288static bool289icon_null(struct icon *icon)290{291 icon->type = ICON_NONE;292 return true;293}294310#if defined(FUZZEL_ENABLE_PNG_LIBPNG)311static bool312icon_from_png_libpng(struct icon *icon, const char *file_name)313{
6 unmodified lines
320 return true;321}322#endif323309static bool324bool325icon_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 lines
364 return true;365}366#endif367353static bool368bool369icon_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 lines
376 return false;377#endif378}379380static bool381svg(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}388389static bool390png(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}397398static void399icon_reset(struct icon *icon)400{401 free(icon->path);402 icon->path = NULL;403404 switch (icon->type) {405 case ICON_NONE:406 break;407
21 unmodified lines
429 free(pixman_image_get_data(rast->pix));430 pixman_image_unref(rast->pix);431 tll_remove(icon->rasterized, it);432 }397 433434 icon->type = ICON_NONE;435}436437static bool402reload_icon(struct icon *icon, int icon_size, icon_theme_list_t themes)438lookup_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;445407 const char *name = icon->name;408 icon_reset(icon);446 char *file_name;447 size_t file_name_len;448410 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 };457413 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();459419 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);463424 return icon_null(icon);425 }464 if (app->icon.name == NULL)465 continue;466427 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");477429 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 }488489 /* For details, see490 * https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup */491431 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;494495 /* 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;499440 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];504443 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);507448 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;510454 /* 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;517459 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;520521 /* 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;527528 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;536537 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 }546547 int dir_fd = openat(548 xdg_dir->fd, theme_relative_path, O_RDONLY | O_DIRECTORY);549 if (dir_fd < 0)550 continue;551552 tll_foreach(icons, icon_it) {553 struct icon_data *icon = &icon_it->item;554555 if (!is_exact_match && icon->min_diff.diff < diff)556 continue;557558 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';564565 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 }572470 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 }583491 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);590497 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);593510 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 }513514 free(full_path);603 }604605 close(dir_fd);606 }607 }518 }608520 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;613525 /* 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 }618530 /* 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;625626 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");633634 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 }652536 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;656538success: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];663664 /* 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 }670671 /* 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 }680681 free(icon->file_name);682 tll_remove(icons, icon_it);683 }684685 return true;686}687688bool544icon_reload_application_icons(icon_theme_list_t themes, int icon_size,689icon_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);695696 return true;697}
modified:icon.h+12 added-2 removed
3 unmodified lines
45#include "application.h"6#include "tllist.h"78enum icon_dir_type {9 ICON_DIR_FIXED,10 ICON_DIR_SCALABLE,11 ICON_DIR_THRESHOLD,12};1314struct 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};2324struct icon_theme {25 char *name;
4 unmodified lines
3031icon_theme_list_t icon_load_theme(const char *name);32void icon_themes_destroy(icon_theme_list_t themes);3327bool icon_reload_application_icons(34bool icon_lookup_application_icons(35 icon_theme_list_t themes, int icon_size,36 struct application_list *applications);3738bool icon_from_png(struct icon *icon, const char *name);39bool icon_from_svg(struct icon *icon, const char *name);
modified:main.c+2 added-2 removed
268 unmodified lines
269 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 lines
401 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 lines
modified:render.c+11 added
12 unmodified lines
13#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"2021#define min(x, y) ((x) < (y) ? (x) : (y))
410 unmodified lines
432render_svg(struct icon *icon, int x, int y, int size, struct buffer *buf)433{434 assert(icon->type == ICON_SVG);435436 if (icon->svg == NULL) {437 if (!icon_from_svg(icon, icon->path))438 return;439 }440441#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 lines
518render_png(struct icon *icon, int x, int y, int size, struct buffer *buf)519{520 assert(icon->type == ICON_PNG);521522 if (icon->png == NULL) {523 if (!icon_from_png(icon, icon->path))524 return;525 }526527#if defined(FUZZEL_ENABLE_PNG_LIBPNG)528 render_png_libpng(icon, x, y, size, buf);529#endif530}
235 unmodified lines
modified:xdg.c+35 added-10 removed
408 unmodified lines
409 application_llist_t apps = tll_init();410411 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);415416 int fd = open(path, O_RDONLY);417 if (fd != -1) {418 scan_dir(fd, terminal, include_actions, &apps, NULL);
75 unmodified lines
494{495 xdg_data_dirs_t ret = tll_init();496497 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());507508 char *path = malloc(strlen(pw->pw_dir) + 1 + strlen(local) + 1);509 sprintf(path, "%s/%s", pw->pw_dir, local);510511 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 }518519 const char *_xdg_data_dirs = getenv("XDG_DATA_DIRS");520
5 unmodified lines
526 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 }536537 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);541542 if (fd1 >= 0) {543 struct xdg_data_dir d = {.fd = fd1, .path = strdup("/usr/local/share")};544 tll_push_back(ret, d);545 }546547 if (fd2 >= 0) {548 struct xdg_data_dir d = {.fd = fd2, .path = strdup("/usr/share")};549 tll_push_back(ret, d);;550 }551 }552553 return ret;554}
1 unmodified line
556void557xdg_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 lines
modified:xdg.h+6 added-2 removed
2 unmodified lines
3#include "application.h"4#include "icon.h"5#include "tllist.h"67typedef tll(char *) xdg_data_dirs_t;8//typedef tll(struct application) application_list_t;7struct xdg_data_dir {8 char *path;9 int fd;10};1112typedef tll(struct xdg_data_dir) xdg_data_dirs_t;1314xdg_data_dirs_t xdg_data_dirs(void);15void xdg_data_dirs_destroy(xdg_data_dirs_t dirs);1617const char *xdg_cache_dir(void);
4 unmodified lines