Skip to content
Myr

icon: search $HOME/.icons, and fix how we search for standalone icons

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

$HOME/.icons should be searched before any of the other XDG data dirs. Also update how we look for standalone (non-theme) icons. Before this patch, we looked for icons in the pixmaps sub-directory, of each XDG data dir. According to https://specifications.freedesktop.org/icon-theme-spec/latest/#directory_layout, this is incorrect; we should only search /usr/share/pixmaps. Furthermore, we should _also_ look for standalone in *all* directories we look for icon themes in. In other words, the directories we look for icons and icon themes are (in this order): * $HOME/.icons * XDG_DATA_DIRS/icons * /usr/share/pixmaps All directories are first searched for an icon in the selected icon theme. If there is no themed icon in any of the above directories, we once again loop the directories, this time looking for a standalone icon.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 8e5ba71 · Browse files · 2 files+51 added−17 removed
This commit

State

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

Diff stats

2 files+51 added−17 removed

  • other:+51 added−17 removed

2 files+51 added−17 removed

modified:CHANGELOG.md+3 added
53 unmodified lines
54 instead of `min(horizontal-pad, vertical-pad)` ([#436][436]).55* `stdout` and `stderr` of the launched application are now preserved,56 instead of being redirected to `/dev/null` ([#480][480]).57* Version 5 of the `wl_seat` interface is now required.58* The `pixmaps` sub-directory is no longer searched for in every59 `XDG_DATA_DIR`; only `/usr/share/pixmaps`.6061[419]: https://codeberg.org/dnkl/fuzzel/issues/41962[439]: https://codeberg.org/dnkl/fuzzel/issues/43963[459]: https://codeberg.org/dnkl/fuzzel/issues/459
17 unmodified lines
81* `wl_seat_release()` used while only binding version 4 of the seat82 interface ([#498][498]).83* Double close of an FD, causing occasional failures to start fuzzel84 ([#497][497]).85* `$HOME/.icons` not searched.8687[426]: https://codeberg.org/dnkl/fuzzel/issues/42688[482]: https://codeberg.org/dnkl/fuzzel/issues/48289[487]: https://codeberg.org/dnkl/fuzzel/issues/487
838 unmodified lines
modified:icon.c+48 added-17 removed
233 unmodified lines
234 }235 }236}237238static xdg_data_dirs_t239get_icon_dirs(void)240{241 /*242 * See https://specifications.freedesktop.org/icon-theme-spec/latest/#directory_layout243 */244245 xdg_data_dirs_t dirs = xdg_data_dirs();246247 const char *home = getenv("HOME");248 if (home != NULL) {249 char *path = xasprintf("%s/%s", home, ".icons");250 int fd = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);251252 if (fd >= 0) {253 struct xdg_data_dir home_icons = {254 .path = path,255 .fd = fd,256 };257258 tll_push_front(dirs, home_icons);259 } else260 free(path);261 }262263 {264 const char *path = "/usr/share/pixmaps";265 int fd = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);266 if (fd >= 0) {267 struct xdg_data_dir home_icons = {268 .path = xstrdup(path),269 .fd = fd,270 };271272 tll_push_back(dirs, home_icons);273 }274 }275276 return dirs;277}278279icon_theme_list_t280icon_load_theme(const char *name)281{282 /* List of themes; first item is the primary theme, subsequent
4 unmodified lines
287 * we go, and find 'Inherits' values in the theme index files. */288 theme_names_t themes_to_load = tll_init();289 tll_push_back(themes_to_load, xstrdup(name));290250 xdg_data_dirs_t dirs = xdg_data_dirs();291 xdg_data_dirs_t dirs = get_icon_dirs();292293 while (tll_length(themes_to_load) > 0) {294 char *theme_name = tll_pop_front(themes_to_load);295
472 unmodified lines
768 tll_foreach(icons, icon_it) {769 const struct icon_data *icon = &icon_it->item;770771 tll_foreach(*xdg_dirs, it) {731 int pixmaps_fd = openat(it->item.fd, "pixmaps", O_RDONLY | O_CLOEXEC);732 if (pixmaps_fd < 0)733 continue;734772 size_t len = icon->file_name_len;773 char *path = icon->file_name;774738 if (!icon_file_exists(pixmaps_fd, path, len)) {739 close(pixmaps_fd);775 if (!icon_file_exists(it->item.fd, path, len))776 continue;741 }777743 close(pixmaps_fd);778 char full_path[strlen(it->item.path) + 1 + len + 1];779745 char full_path[strlen(it->item.path) + 1 +746 strlen("pixmaps") + 1 +747 len + 1];748780 /* Try SVG variant first */750 sprintf(full_path, "%s/pixmaps/%s", it->item.path, path);781 sprintf(full_path, "%s/%s", it->item.path, path);782 if (path[len - 3] == 's' && svg(&icon->app->icon, full_path)) {752 LOG_DBG("%s: %s (pixmaps)", icon->name, full_path);783 LOG_DBG("%s: %s (standalone)", icon->name, full_path);784 break;785 }786787 /* No SVG, look for PNG instead */788 if (path[len - 3] == 'p' && png(&icon->app->icon, full_path)) {758 LOG_DBG("%s: %s (pixmaps)", icon->name, full_path);789 LOG_DBG("%s: %s (standalone)", icon->name, full_path);790 break;791 }792793 }
8 unmodified lines
802bool803icon_lookup_application_icons(icon_theme_list_t themes, int icon_size,804 struct application_list *applications)805{775 xdg_data_dirs_t xdg_dirs = xdg_data_dirs();806 xdg_data_dirs_t xdg_dirs = get_icon_dirs();807 lookup_icons(&themes, icon_size, applications, &xdg_dirs);808 xdg_data_dirs_destroy(xdg_dirs);809810 return true;
1 unmodified line