Skip to content
Myr

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

7 files+65 added−15 removed

modified:doc/fuzzel.1.scd+6 added
196 unmodified lines
197 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 --dmenu207208*--index*209 Print selected entry's index instead of its text. **dmenu** mode210 only.
69 unmodified lines
modified:CHANGELOG.md+3 added
36 unmodified lines
37 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]).4344[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/166505152### Changed53
345 unmodified lines
modified:dmenu.c+28 added-9 removed
18 unmodified lines
1920void21dmenu_load_entries(struct application_list *applications, int abort_fd)22{23 tll(char32_t *) entries = tll_init();23 tll(struct application) entries = tll_init();2425 char *line = NULL;26 size_t alloc_size = 0;27
28 unmodified lines
56 break;5758 ssize_t len = getline(&line, &alloc_size, stdin);5960 if (len == -1) {60 if (len < 0) {61 if (errno != 0)62 LOG_ERRNO("failed to read from stdin");63 break;64 }6566 while (len > 0 && line[len - 1] == '\n')67 line[--len] = '\0';6869 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 }8485 LOG_DBG("%s (icon=%s)", line, icon_name);8687 char32_t *wline = ambstoc32(line);88 if (wline == NULL)89 continue;9091 struct application app = {92 .title = wline,93 .icon = {.name = icon_name != NULL ? strdup(icon_name) : NULL},94 .visible = true,95 };9675 tll_push_back(entries, wline);97 tll_push_back(entries, app);98 }99100 free(line);101
1 unmodified line
103104 applications->v = calloc(tll_length(entries), sizeof(applications->v[0]));105 applications->count = tll_length(entries);106107 /* 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;91110 applications->v[i++] = it->item;111 tll_remove(entries, it);112 }113114 tll_free(entries);
22 unmodified lines
modified:main.c+12 added-5 removed
374 unmodified lines
375 bool actions_enabled = ctx->conf->actions_enabled;376 bool dmenu_enabled = ctx->conf->dmenu.enabled;377 bool icons_enabled = ctx->conf->icons_enabled;378379 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 }385384 xdg_find_programs(terminal, actions_enabled, apps);385 read_cache(apps);386386 int r = send_event(ctx->event_fd, EVENT_APPS_LOADED);387 if (r != 0)388 return r;389
784 unmodified lines
1174 dmenu_load_entries(apps, -1);1175 if (apps->count == 0)1176 goto out;11771178 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 }11851186 matches_set_applications(matches, apps);1187 matches_update(matches, prompt);1188 }1189
118 unmodified lines
modified:match.c+14 added
208 unmodified lines
209 matches->matches = calloc(210 applications->count, sizeof(matches->matches[0]));211}212213bool214matches_have_icons(const struct matches *matches)215{216 if (matches->applications == NULL)217 return false;218219 for (size_t i = 0; i < matches->applications->count; i++) {220 if (matches->applications->v[i].icon.name != NULL)221 return true;222 }223224 return false;225}226227size_t228matches_max_matches_per_page(const struct matches *matches)229{230 return matches->max_matches_per_page;
452 unmodified lines
modified:match.h+1 added
33 unmodified lines
34void matches_destroy(struct matches *matches);3536void matches_set_applications(37 struct matches *matches, const struct application_list *applications);38bool matches_have_icons(const struct matches *matches);3940size_t matches_max_matches_per_page(const struct matches *matches);41void matches_max_matches_per_page_set(42 struct matches *matches, size_t max_matches);
16 unmodified lines
modified:render.c+1 added-1 removed
683 unmodified lines
684 const struct fcft_glyph *space = fcft_rasterize_char_utf32(685 font, U' ', subpixel);686687 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