Merge branch 'dmenu-icons'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Daniel Eklöf · committed by Daniel Eklöf · parents 6400458, a29e168 · Browse files · 7 files·+65 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+65 added−15 removed
- other:+65 added−15 removed
Provenance
- Commit
5c3cce7- Tree
82e5045- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent 1
6400458- Parent 2
a29e168
7 files changed+65 added−15 removed
modified:doc/fuzzel.1.scd+6 added
196 unmodified lines197 198 Alternatively, you can symlink the fuzzel binary to199 *dmenu*. Fuzzel will then start in dmenu mode, without the200 *--dmenu* argument.201+ 202+ Fuzzel also supports icons, using Rofi's extended dmenu203+ protocol. To set an icon for an entry, append204+ *\\0icon\\x1f<icon-name>*. Example:205+ 206+ echo -en "Firefox\\0icon\\x1ffirefox" | fuzzel --dmenu207 208 *--index*209 Print selected entry's index instead of its text. **dmenu** mode210 only.69 unmodified linesmodified:CHANGELOG.md+3 added
36 unmodified lines37 matched substrings of the currently selected item38 * New config option `image-size-ratio`, allowing you to control the39 size of the large image displayed when there are only a “few”40 matches.41+* Support for icons in dmenu mode, using Rofi’s extended dmenu42+ protocol ([#166][166]).43 44 [3]: https://codeberg.org/dnkl/fuzzel/issues/345 [107]: https://codeberg.org/dnkl/fuzzel/issues/10746 [108]: https://codeberg.org/dnkl/fuzzel/issues/10847 [120]: https://codeberg.org/dnkl/fuzzel/issues/12048 [143]: https://codeberg.org/dnkl/fuzzel/issues/14349+[166]: https://codeberg.org/dnkl/fuzzel/issues/16650 51 52 ### Changed53 345 unmodified linesmodified:dmenu.c+28 added-9 removed
18 unmodified lines19 20 void21 dmenu_load_entries(struct application_list *applications, int abort_fd)22 {23- tll(char32_t *) entries = tll_init();23+ tll(struct application) entries = tll_init();24 25 char *line = NULL;26 size_t alloc_size = 0;27 28 unmodified lines56 break;57 58 ssize_t len = getline(&line, &alloc_size, stdin);59 60- if (len == -1) {60+ if (len < 0) {61 if (errno != 0)62 LOG_ERRNO("failed to read from stdin");63 break;64 }65 66 while (len > 0 && line[len - 1] == '\n')67 line[--len] = '\0';68 69- LOG_DBG("%s", line);69+ /*70+ * Support Rofi’s extended dmenu protocol. One can specify an71+ * icon by appending ‘\0icon\x1f<icon-name>’ to the entry:72+ *73+ * “hello world\0icon\x1ffirefox”74+ */75+ const char *icon_name = NULL;76+ const char *extra = strchr(line, '\0');77+ if (extra != NULL && strncmp(extra + 1, "icon", 4) == 0) {78+ char *separator = strchr(extra + 1, '\x1f');79+ if (separator != NULL) {80+ *separator = '\0';81+ icon_name = separator + 1;82+ }83+ }84 85+ LOG_DBG("%s (icon=%s)", line, icon_name);86+87 char32_t *wline = ambstoc32(line);88 if (wline == NULL)89 continue;90 91+ struct application app = {92+ .title = wline,93+ .icon = {.name = icon_name != NULL ? strdup(icon_name) : NULL},94+ .visible = true,95+ };96+75- tll_push_back(entries, wline);97+ tll_push_back(entries, app);98 }99 100 free(line);101 1 unmodified line103 104 applications->v = calloc(tll_length(entries), sizeof(applications->v[0]));105 applications->count = tll_length(entries);106 107+ /* Convert linked-list to regular array */108 size_t i = 0;109 tll_foreach(entries, it) {87- struct application *app = &applications->v[i++];88- app->title = it->item;89- app->icon.type = ICON_NONE;90- app->visible = true;91-110+ applications->v[i++] = it->item;111 tll_remove(entries, it);112 }113 114 tll_free(entries);22 unmodified linesmodified:main.c+12 added-5 removed
374 unmodified lines375 bool actions_enabled = ctx->conf->actions_enabled;376 bool dmenu_enabled = ctx->conf->dmenu.enabled;377 bool icons_enabled = ctx->conf->icons_enabled;378 379- if (dmenu_enabled) {379+ if (dmenu_enabled)380 dmenu_load_entries(apps, ctx->dmenu_abort_fd);381- return send_event(ctx->event_fd, EVENT_APPS_LOADED);381+ else {382+ xdg_find_programs(terminal, actions_enabled, apps);383+ read_cache(apps);384 }385 384- xdg_find_programs(terminal, actions_enabled, apps);385- read_cache(apps);386-386 int r = send_event(ctx->event_fd, EVENT_APPS_LOADED);387 if (r != 0)388 return r;389 784 unmodified lines1174 dmenu_load_entries(apps, -1);1175 if (apps->count == 0)1176 goto out;1177 1178+ if (conf.icons_enabled) {1179+ themes = icon_load_theme(conf.icon_theme);1180+ if (tll_length(themes) > 0)1181+ LOG_INFO("theme: %s", tll_front(themes).name);1182+ else1183+ LOG_WARN("%s: icon theme not found", conf.icon_theme);1184+ }1185+1186 matches_set_applications(matches, apps);1187 matches_update(matches, prompt);1188 }1189 118 unmodified linesmodified:match.c+14 added
208 unmodified lines209 matches->matches = calloc(210 applications->count, sizeof(matches->matches[0]));211 }212 213+bool214+matches_have_icons(const struct matches *matches)215+{216+ if (matches->applications == NULL)217+ return false;218+219+ for (size_t i = 0; i < matches->applications->count; i++) {220+ if (matches->applications->v[i].icon.name != NULL)221+ return true;222+ }223+224+ return false;225+}226+227 size_t228 matches_max_matches_per_page(const struct matches *matches)229 {230 return matches->max_matches_per_page;452 unmodified linesmodified:match.h+1 added
33 unmodified lines34 void matches_destroy(struct matches *matches);35 36 void matches_set_applications(37 struct matches *matches, const struct application_list *applications);38+bool matches_have_icons(const struct matches *matches);39 40 size_t matches_max_matches_per_page(const struct matches *matches);41 void matches_max_matches_per_page_set(42 struct matches *matches, size_t max_matches);16 unmodified linesmodified:render.c+1 added-1 removed
683 unmodified lines684 const struct fcft_glyph *space = fcft_rasterize_char_utf32(685 font, U' ', subpixel);686 687 cur_x +=688- (!render->conf->dmenu.enabled688+ (render->conf->icons_enabled && matches_have_icons(matches)689 ? (row_height +690 (space != NULL ? space->advance.x : font->max_advance.x))691 : 0) +692 pt_or_px_as_pixels(render, &render->conf->letter_spacing);127 unmodified lines