render: display match+total entry count
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 · parent 0c3be18 · Browse files · 11 files·+187 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+187 added−19 removed
- other:+187 added−19 removed
Provenance
- Commit
b32836d- Tree
639903e- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
0c3be18
11 files changed+187 added−19 removed
modified:completions/fish/fuzzel.fish+1 added
39 unmodified lines40 complete -c fuzzel -x -s m -l match-color -d "color of matched substring (cb4b16ff)"41 complete -c fuzzel -x -s s -l selection-color -d "background color of selected item (eee8d5dd)"42 complete -c fuzzel -x -s S -l selection-text-color -d "text color of selected item (657b83ff)"43 complete -c fuzzel -x -s M -l selection-match-color -d "color of matched substring of selected item (cb4b16ff)"44+complete -c fuzzel -x -l count-color -d "color of the match count (93a1a1ff)"45 complete -c fuzzel -x -s B -l border-width -d "width of border, in pixels (1)"46 complete -c fuzzel -x -s r -l border-radius -d "amount of corner \"roundness\" (10)"47 complete -c fuzzel -x -s C -l border-color -d "border color (002b36ff)"48 complete -c fuzzel -l show-actions -d "include desktop actions (e.g. \"New Window\") in the list"22 unmodified linesmodified:completions/zsh/_fuzzel+1 added
31 unmodified lines32 '(-m --match-color)'{-m,--match-color}'[color of matched substring (cb4b16ff)]:match-color:()' \33 '(-s --selection-color)'{-s,--selection-color}'[background color of selected item (eee8d5dd)]:selection-color:()' \34 '(-S --selection-text-color)'{-S,--selection-text-color}'[text color of selected item (657b83ff)]:selection-text-color:()' \35 '(-M --selection-match-color)'{-M,--selection-match-color}'[color of matched substring of selected item (cb4b16ff)]:match-color:()' \36+ '--count-color[color of the match count (93a1a1ff)]:count-color:()' \37 '(-B --border-width)'{-B,--border-width}'[width of border, in pixels (1)]:border-width:()' \38 '(-r --border-radius)'{-r,--border-radius}'[amount of corner "roundness" (10)]:border-radius:()' \39 '(-C --border-color)'{-C,--border-color}'[border color (002b36ff)]:border-color:()' \40 '--show-actions[include desktop actions (e.g "New Window") in the list]' \40 unmodified linesmodified:doc/fuzzel.1.scd+4 added
211 unmodified lines212 application. As you start typing in the search box, the matching213 part in each application's name is highlighted with this color.214 See *COLORS*. Default: _cb4b16ff_.215 216+*--count-color*=_HEX_217+ The color of the match count stats printed at the right-hand side218+ of the input prompt. See *COLORS*. Default: _93a1a1ff_.219+220 *-B*,*--border-width*=_INT_221 The width of the surrounding border, in pixels (subject to output222 scaling). Default: _1_.223 190 unmodified linesmodified:doc/fuzzel.ini.5.scd+4 added
304 unmodified lines305 *selection-match*306 Text (foreground) color of the matched substring of the307 selected entry. Default: _cb4b16ff_.308 309+*count*=_HEX_310+ The color of the match count stats printed at the right-hand side311+ of the input prompt. See *COLORS*. Default: _93a1a1ff_.312+313 *border*314 Border color. Default: _002b36ff_.315 316 175 unmodified linesmodified:CHANGELOG.md+5 added
63 unmodified lines64 option in `fuzzel.ini`.65 * `delayed-filter-ms`, `delayed-filter-limit` options to `fuzzel.ini`,66 and `--delayed-filter-ms` and `--delayed-filter-limit` command line67 options.68+* Match count is now printed at the right-hand side of the input69+ prompt.70+* `--count-color` and `colors.count`, controlling the color of the71+ match count. The default value is `93a1a1ff` (_base1_ in the72+ solarized palette).73 74 [344]: https://codeberg.org/dnkl/fuzzel/issues/34475 [131]: https://codeberg.org/dnkl/fuzzel/issues/13176 [189]: https://codeberg.org/dnkl/fuzzel/issues/189700 unmodified linesmodified:config.c+4 added
1029 unmodified lines1030 1031 else if (strcmp(key, "selection-match") == 0)1032 return value_to_color(ctx, true, &conf->colors.selection_match);1033 1034+ else if (strcmp(key, "count") == 0)1035+ return value_to_color(ctx, true, &conf->colors.count);1036+1037 else if (strcmp(key, "border") == 0)1038 return value_to_color(ctx, true, &conf->colors.border);1039 1040 else585 unmodified lines1626 .match = conf_hex_to_rgba(0xcb4b16ff),1627 .selection = conf_hex_to_rgba(0xeee8d5dd),1628 .selection_text = conf_hex_to_rgba(0x657b83ff),1629 .selection_match = conf_hex_to_rgba(0xcb4b16ff),1630+ .count = conf_hex_to_rgba(0x93a1a1ff),1631 },1632 .border = {1633 .size = 1u,1634 .radius = 10u,87 unmodified linesmodified:config.h+1 added
169 unmodified lines170 struct rgba match;171 struct rgba selection;172 struct rgba selection_text;173 struct rgba selection_match;174+ struct rgba count;175 } colors;176 177 struct {178 unsigned size;22 unmodified linesmodified:fuzzel.ini+1 added
43 unmodified lines44 # match=cb4b16ff45 # selection=eee8d5dd46 # selection-text=657b83ff47 # selection-match=cb4b16ff48+# count=93a1a1ff49 # border=002b36ff50 51 [border]52 # width=154 unmodified linesmodified:main.c+37 added-12 removed
352 unmodified lines353 " -s,--selection-color=HEX background color of selected item (eee8d5dd)\n"354 " -S,--selection-text-color=HEX text color of selected item (657b83ff)\n"355 " -M,--selection-match-color=HEX color of matched substring in selection\n"356 " (cb4b16ff)\n"357+ " --count-color color of the match count (93a1a1)\n"358 " -B,--border-width=INT width of border, in pixels (1)\n"359 " -r,--border-radius=INT amount of corner \"roundness\" (10)\n"360 " -C,--border-color=HEX border color (002b36ff)\n"361 " --show-actions include desktop actions in the list\n"334 unmodified lines696 #define OPT_RENDER_WORKERS 281697 #define OPT_PROMPT_COLOR 282698 #define OPT_INPUT_COLOR 283699 #define OPT_PROMPT_ONLY 284700+ #define OPT_COUNT_COLOR 285701 #define OPT_MATCH_WORKERS 287702 #define OPT_DELAYED_FILTER_MS 289703 #define OPT_DELAYED_FILTER_LIMIT 290704 25 unmodified lines730 {"match-color", required_argument, 0, 'm'},731 {"selection-color", required_argument, 0, 's'},732 {"selection-text-color", required_argument, 0, 'S'},733 {"selection-match-color",required_argument, 0, 'M'},734+ {"count-color", required_argument, 0, OPT_COUNT_COLOR},735 {"border-width", required_argument, 0, 'B'},736 {"border-radius", required_argument, 0, 'r'},737 {"border-color", required_argument, 0, 'C'},738 {"prompt", required_argument, 0, 'p'},62 unmodified lines801 bool match_color_set:1;802 bool selection_color_set:1;803 bool selection_text_color_set:1;804 bool selection_match_color_set:1;805+ bool count_color_set:1;806 bool border_color_set:1;807 bool border_size_set:1;808 bool border_radius_set:1;809 bool actions_enabled_set:1;433 unmodified lines1243 cmdline_overrides.selection_match_color_set = true;1244 break;1245 }1246 1247+ case OPT_COUNT_COLOR: {1248+ const char *clr_start = optarg;1249+ if (clr_start[0] == '#')1250+ clr_start++;1251+1252+ errno = 0;1253+ char *end = NULL;1254+ uint32_t count_color = strtoul(clr_start, &end, 16);1255+ if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1256+ fprintf(stderr, "count-color: %s: invalid color\n",1257+ optarg);1258+ return EXIT_FAILURE;1259+ }1260+ cmdline_overrides.conf.colors.count = conf_hex_to_rgba(count_color);1261+ cmdline_overrides.count_color_set = true;1262+ break;1263+ }1264+1265+1266 case 'B':1267 if (sscanf(optarg, "%u", &cmdline_overrides.conf.border.size) != 1) {1268 fprintf(1269 stderr,34 unmodified lines1304 cmdline_overrides.actions_enabled_set = true;1305 cmdline_overrides.conf.actions_enabled = true;1306 break;1307 1285- case OPT_FILTER_DESKTOP:1286- cmdline_overrides.filter_desktop_set = true;1287- if (optarg != NULL && strcasecmp(optarg, "no") == 0)1288- cmdline_overrides.conf.filter_desktop = false;1289- else if (optarg != NULL) {1290- fprintf(stderr, "%s: invalid filter-desktop option\n", optarg);1291- return EXIT_FAILURE;1292- }1293- else1294- cmdline_overrides.conf.filter_desktop = true;1295- break;1296-1308 case OPT_MATCH_MODE:1309 if (strcmp(optarg, "exact") == 0)1310 cmdline_overrides.conf.match_mode = MATCH_MODE_EXACT;1311 else if (strcmp(optarg, "fzf") == 0)7 unmodified lines1319 1320 cmdline_overrides.match_mode_set = true;1321 break;1322 1323+ case OPT_FILTER_DESKTOP:1324+ cmdline_overrides.filter_desktop_set = true;1325+ if (optarg != NULL && strcasecmp(optarg, "no") == 0)1326+ cmdline_overrides.conf.filter_desktop = false;1327+ else if (optarg != NULL) {1328+ fprintf(stderr, "%s: invalid filter-desktop option\n", optarg);1329+ return EXIT_FAILURE;1330+ }1331+ else1332+ cmdline_overrides.conf.filter_desktop = true;1333+ break;1334+1335 case OPT_FUZZY_MIN_LENGTH:1336 if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.min_length) != 1) {1337 fprintf(1338 stderr,273 unmodified lines1612 if (cmdline_overrides.selection_text_color_set)1613 conf.colors.selection_text = cmdline_overrides.conf.colors.selection_text;1614 if (cmdline_overrides.selection_match_color_set)1615 conf.colors.selection_match = cmdline_overrides.conf.colors.selection_match;1616+ if (cmdline_overrides.count_color_set)1617+ conf.colors.count = cmdline_overrides.conf.colors.count;1618 if (cmdline_overrides.border_color_set)1619 conf.colors.border = cmdline_overrides.conf.colors.border;1620 if (cmdline_overrides.border_size_set)1621 conf.border.size = cmdline_overrides.conf.border.size;272 unmodified linesmodified:render.c+128 added-6 removed
60 unmodified lines61 pixman_color_t pix_match_color;62 pixman_color_t pix_selection_color;63 pixman_color_t pix_selection_text_color;64 pixman_color_t pix_selection_match_color;65+ pixman_color_t pix_count_color;66 67 unsigned x_margin;68 unsigned y_margin;69 unsigned inner_pad;154 unmodified lines224 pixman_image_unref(src);225 }226 }227 228+static int229+render_match_count(const struct render *render, struct buffer *buf,230+ const struct prompt *prompt, const struct matches *matches)231+{232+ struct fcft_font *font = render->font;233+ assert(font != NULL);234+235+ const struct config *conf = render->conf;236+237+ const enum fcft_subpixel subpixel =238+ conf->colors.background.a == 1. && conf->colors.selection.a == 1.239+ ? render->subpixel240+ : FCFT_SUBPIXEL_NONE;241+242+ size_t total_count = matches_get_application_count(matches);243+ size_t match_count = matches_get_total_count(matches);244+ const char32_t *ptext = prompt_text(prompt);245+246+ char *text = NULL;247+ int chars = asprintf(248+ &text, "%zu/%zu",249+ ptext[0] == U'\0' ? total_count : match_count, total_count);250+251+ if (chars < 0)252+ return 0;253+254+ /* fcft wants UTF-32. Since we only use ASCII... */255+ uint32_t *wtext = malloc(chars * sizeof(wtext[0]));256+ for (size_t i = 0; i < chars; i++)257+ wtext[i] = (uint32_t)(unsigned char)text[i];258+259+ int width = -1;260+ int x = buf->width - render->border_size - render->x_margin;261+ int y = render->border_size + render->y_margin +262+ (render->row_height + font->height) / 2 - font->descent;263+264+ if (fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING) {265+ struct fcft_text_run *run = fcft_rasterize_text_run_utf32(266+ font, chars, wtext, subpixel);267+268+ if (run != NULL) {269+ width = 0;270+271+ for (size_t i = 0; i < run->count; i++) {272+ const struct fcft_glyph *glyph = run->glyphs[i];273+ width += glyph->advance.x;274+ }275+276+ x -= width;277+ for (size_t i = 0; i < run->count; i++) {278+ const struct fcft_glyph *glyph = run->glyphs[i];279+ render_glyph(buf->pix[0], glyph, x, y, &render->pix_count_color);280+ x += glyph->advance.x;281+ }282+283+ fcft_text_run_destroy(run);284+ free(text);285+ free(wtext);286+ return width;287+ }288+ }289+290+ const struct fcft_glyph **glyphs = malloc(chars * sizeof(glyphs[0]));291+ long *x_kern = malloc(chars * sizeof(x_kern[0]));292+ char32_t prev;293+294+ width = 0;295+ for (size_t i = 0; i < (size_t)chars; i++) {296+ x_kern[i] = 0;297+298+ const struct fcft_glyph *glyph =299+ fcft_rasterize_char_utf32(font, wtext[i], subpixel);300+ glyphs[i] = glyph;301+302+ if (glyph == NULL)303+ continue;304+305+ if (i > 0) {306+ if (fcft_kerning(font, prev, wtext[i], &x_kern[i], NULL))307+ width += x_kern[i];308+ }309+ width += glyph->advance.x;310+ prev = wtext[i];311+ }312+313+ x -= width;314+315+ for (size_t i = 0; i < (size_t)chars; i++) {316+ const struct fcft_glyph *glyph = glyphs[i];317+ if (glyph == NULL)318+ continue;319+320+ x += x_kern[i];321+ render_glyph(buf->pix[0], glyph, x, y, &render->pix_count_color);322+ x += glyph->advance.x;323+ prev = wtext[i];324+ }325+326+ free(x_kern);327+ free(glyphs);328+ free(text);329+ free(wtext);330+ return width;331+}332+333 void334 render_prompt(const struct render *render, struct buffer *buf,229- const struct prompt *prompt)335+ const struct prompt *prompt, const struct matches *matches)336 {337 struct fcft_font *font = render->font;338 assert(font != NULL);339 11 unmodified lines351 ? render->subpixel : FCFT_SUBPIXEL_NONE;352 353 int x = render->border_size + render->x_margin;354 int y = render->border_size + render->y_margin +249- (render->row_height + font->height) / 2 - font->descent;355+ (render->row_height + font->height) / 2 - font->descent;356 357+ int stats_width = render_match_count(render, buf, prompt, matches);358+359+ const int max_x =360+ buf->width - render->border_size - render->x_margin - stats_width;361+362 if (fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING) {363 struct fcft_text_run *run = fcft_rasterize_text_run_utf32(364 font, prompt_len, pprompt, subpixel);365 366 if (run != NULL) {367 for (size_t i = 0; i < run->count; i++) {368 const struct fcft_glyph *glyph = run->glyphs[i];369+ if (x + glyph->width > max_x)370+ return;371+372 render_glyph(buf->pix[0], glyph, x, y, &render->pix_prompt_color);373 x += glyph->advance.x;374 }375 fcft_text_run_destroy(run);40 unmodified lines416 long x_kern;417 fcft_kerning(font, prev, wc, &x_kern, NULL);418 419 x += x_kern;306- render_glyph(buf->pix[0], glyph, x, y, &render->pix_input_color);420+421+ if (x + glyph->width >= max_x)422+ return;423+424+ render_glyph(425+ buf->pix[0], glyph, x, y,426+ use_placholder427+ ? &render->pix_placeholder_color428+ : &render->pix_input_color);429 x += glyph->advance.x;430 if (i >= prompt_len)431 x += pt_or_px_as_pixels(render, &render->conf->letter_spacing);432 432 unmodified lines865 break;866 }867 }868 747- const struct fcft_glyph *space = fcft_rasterize_char_utf32(748- render->font, U' ', subpixel);869+ const struct fcft_glyph *space =870+ fcft_rasterize_char_utf32(render->font, U' ', subpixel);871 872 cur_x +=873 (render->conf->icons_enabled && matches_have_icons(matches)874 ? (render->row_height +188 unmodified lines1063 render->pix_match_color = rgba2pixman(render->conf->colors.match);1064 render->pix_selection_color = rgba2pixman(render->conf->colors.selection);1065 render->pix_selection_text_color = rgba2pixman(render->conf->colors.selection_text);1066 render->pix_selection_match_color = rgba2pixman(render->conf->colors.selection_match);1067+ render->pix_count_color = rgba2pixman(render->conf->colors.count);1068 1069 if (sem_init(&render->workers.start, 0, 0) < 0 ||1070 sem_init(&render->workers.done, 0, 0) < 0)1071 {4 unmodified lines1076 int err;1077 if ((err = mtx_init(&render->workers.lock, mtx_plain)) != thrd_success) {1078 LOG_ERR("failed to instantiate render worker mutex: %d", err);1079 goto err_free_semaphores;957- return NULL;1080 }1081 1082 render->workers.threads = calloc(render->conf->render_worker_count,1083 sizeof(render->workers.threads[0]));181 unmodified linesmodified:render.h+1 added-1 removed
22 unmodified lines23 void render_background(const struct render *render, struct buffer *buf);24 25 void render_prompt(26 const struct render *render, struct buffer *buf,27- const struct prompt *prompt);27+ const struct prompt *prompt, const struct matches *matches);28 29 void render_match_list(30 struct render *render, struct buffer *buf,31 const struct prompt *prompt, const struct matches *matches);6 unmodified lines