Skip to content
Myr

feat: border radius for selected entries

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

fixup: defaults fixup: apply change requests fixup: formatting, missed one fixup: optimize rendering fix: free selection_corners fix: gaps caused by blt fixup: default selection-radius to 0 fixup: fix memory leak fixup: use composite instead of blit fixup: remove flake.nix... fixup: don't hardcode buffer format fixup: limit radius when horizontal padding is small fixup: replace tabs with spaces fixup: don't hardcode format

authored by wispl · committed by wispl · parent 04f7d64 · Browse files · 9 files+111 added−41 removed
This commit

State

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

Trailers

  • fixup: wrong variable

Diff stats

9 files+111 added−41 removed

  • other:+111 added−41 removed

9 files+111 added−41 removed

modified:completions/fish/fuzzel.fish+1 added
51 unmodified lines
52complete -c fuzzel -x -s m -l match-color -d "color of matched substring (cb4b16ff)"53complete -c fuzzel -x -s s -l selection-color -d "background color of selected item (eee8d5ff)"54complete -c fuzzel -x -s S -l selection-text-color -d "text color of selected item (586e75ff)"55complete -c fuzzel -x -s M -l selection-match-color -d "color of matched substring of selected item (cb4b16ff)"56complete -c fuzzel -x -l selection-radius -d "amount of corner \"roundness\" for the selected entry (0)"57complete -c fuzzel -x -l counter-color -d "color of the match count (93a1a1ff)"58complete -c fuzzel -x -s B -l border-width -d "width of border, in pixels (1)"59complete -c fuzzel -x -s r -l border-radius -d "amount of corner \"roundness\" (10)"60complete -c fuzzel -x -s C -l border-color -d "border color (002b36ff)"
31 unmodified lines
modified:completions/zsh/_fuzzel+1 added
43 unmodified lines
44 '(-m --match-color)'{-m,--match-color}'[color of matched substring (cb4b16ff)]:match-color:()' \45 '(-s --selection-color)'{-s,--selection-color}'[background color of selected item (eee8d5ff)]:selection-color:()' \46 '(-S --selection-text-color)'{-S,--selection-text-color}'[text color of selected item (586e75ff)]:selection-text-color:()' \47 '(-M --selection-match-color)'{-M,--selection-match-color}'[color of matched substring of selected item (cb4b16ff)]:match-color:()' \48 '--selection-radius[amount of corner "roundness" for the selected entry (0)]:selection-radius:()' \49 '--counter-color[color of the match count (93a1a1ff)]:counter-color:()' \50 '(-B --border-width)'{-B,--border-width}'[width of border, in pixels (1)]:border-width:()' \51 '(-r --border-radius)'{-r,--border-radius}'[amount of corner "roundness" (10)]:border-radius:()' \52 '(-C --border-color)'{-C,--border-color}'[border color (002b36ff)]:border-color:()' \
49 unmodified lines
modified:doc/fuzzel.1.scd+5 added
302 unmodified lines
303 application. As you start typing in the search box, the matching304 part in each application's name is highlighted with this color.305 See *COLORS*. Default: _cb4b16ff_.306307*--selection-radius*=_INT_308 The border radius of the selection entry. Like border-radius, this is309 subjected to output scaling. A larger value means a rounder corner. 0310 disables rounded corner. Default: _0_.311312*--counter-color*=_HEX_313 The color of the match count stats printed at the right-hand side314 of the input prompt. See *COLORS*. Default: _93a1a1ff_.315
278 unmodified lines
modified:doc/fuzzel.ini.5.scd+4 added
472 unmodified lines
473474*radius*475 Amount of corner "roundness". Default: _10_.476477*selection-radius*478 Amount of corner "roundness" for the selected entry. Default: _0_.479480481# SECTION: dmenu482483*mode*484 One of *text* or *index*. Determines what fuzzel prints on stdout
224 unmodified lines
modified:CHANGELOG.md+2 added
55 unmodified lines
56 window size while still accepting input. This cannot be used57 simultaneously with `--prompt-only`.i ([#597][597])58* `--auto-select` option. When one entry is left, automatically select59 it. ([#411][411])60* `selection-radius` option and `--selection-radius` flag to set the border61 radius of the selected entry6263[411]: https://codeberg.org/dnkl/fuzzel/issues/41164[504]: https://codeberg.org/dnkl/fuzzel/pulls/50465[512]: https://codeberg.org/dnkl/fuzzel/pulls/512
979 unmodified lines
modified:config.c+7 added
1098 unmodified lines
10991100 else if (strcmp(key, "radius") == 0)1101 return value_to_uint32(ctx, 10, &conf->border.radius);11021103 else if (strcmp(key, "selection-radius") == 0)1104 return value_to_uint32(ctx, 10, &conf->selection_border.radius);11051106 else1107 LOG_CONTEXTUAL_ERR("not a valid option: %s", key);11081109 return false;
580 unmodified lines
1690 .border = {1691 .size = 1u,1692 .radius = 10u,1693 },1694 .selection_border = {1695 .size = 0u,1696 .radius = 0u,1697 },1698 .image_size_ratio = 0.5,1699 .png_scaling_filter = SCALING_FILTER_BOX,1700 .line_height = {-1, 0.0},1701 .letter_spacing = {0},
88 unmodified lines
modified:config.h+1 added-1 removed
203 unmodified lines
204205 struct {206 unsigned size;207 unsigned radius;208 } border;208 } border, selection_border;209210 float image_size_ratio;211212 enum scaling_filter png_scaling_filter;
23 unmodified lines
modified:main.c+16 added
395 unmodified lines
396 " -s,--selection-color=HEX background color of selected item (eee8d5ff)\n"397 " -S,--selection-text-color=HEX text color of selected item (586e75ff)\n"398 " -M,--selection-match-color=HEX color of matched substring in selection\n"399 " (cb4b16ff)\n"400 " --selection-radius border radius of the selected entry (0)\n"401 " --counter-color color of the match count (93a1a1)\n"402 " -B,--border-width=INT width of border, in pixels (1)\n"403 " -r,--border-radius=INT amount of corner \"roundness\" (10)\n"404 " -C,--border-color=HEX border color (002b36ff)\n"
436 unmodified lines
841 #define OPT_SCALING_FILTER 302842 #define OPT_MINIMAL_LINES 303843 #define OPT_HIDE_PROMPT 304844 #define OPT_AUTO_SELECT 305845 #define OPT_SELECTION_RADIUS 306846847 static const struct option longopts[] = {848 {"config", required_argument, 0, OPT_CONFIG},849 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},
30 unmodified lines
880 {"match-color", required_argument, 0, 'm'},881 {"selection-color", required_argument, 0, 's'},882 {"selection-text-color", required_argument, 0, 'S'},883 {"selection-match-color",required_argument, 0, 'M'},884 {"selection-radius", required_argument, 0, OPT_SELECTION_RADIUS},885 {"counter-color", required_argument, 0, OPT_COUNTER_COLOR},886 {"border-width", required_argument, 0, 'B'},887 {"border-radius", required_argument, 0, 'r'},888 {"border-color", required_argument, 0, 'C'},
76 unmodified lines
965 bool match_color_set:1;966 bool selection_color_set:1;967 bool selection_text_color_set:1;968 bool selection_match_color_set:1;969 bool selection_border_radius_set:1;970 bool counter_color_set:1;971 bool border_color_set:1;972 bool border_size_set:1;973 bool border_radius_set:1;
500 unmodified lines
1474 cmdline_overrides.selection_text_color_set = true;1475 break;1476 }14771478 case OPT_SELECTION_RADIUS: {1479 if (sscanf(optarg, "%u", &cmdline_overrides.conf.selection_border.radius) != 1) {1480 fprintf(stderr, "%s: invalid selection border radius (must be an integer)\n",1481 optarg);1482 return EXIT_FAILURE;1483 }1484 cmdline_overrides.selection_border_radius_set = true;1485 break;1486 }14871488 case 'M': {1489 const char *clr_start = optarg;1490 if (clr_start[0] == '#')1491 clr_start++;
499 unmodified lines
1991 if (cmdline_overrides.selection_text_color_set)1992 conf.colors.selection_text = cmdline_overrides.conf.colors.selection_text;1993 if (cmdline_overrides.selection_match_color_set)1994 conf.colors.selection_match = cmdline_overrides.conf.colors.selection_match;1995 if (cmdline_overrides.selection_border_radius_set)1996 conf.selection_border.radius = cmdline_overrides.conf.selection_border.radius;1997 if (cmdline_overrides.counter_color_set)1998 conf.colors.counter = cmdline_overrides.conf.colors.counter;1999 if (cmdline_overrides.border_color_set)2000 conf.colors.border = cmdline_overrides.conf.colors.border;
279 unmodified lines
modified:render.c+74 added-40 removed
59 unmodified lines
60 /* Cached fcft text runs */61 struct fcft_text_run *prompt_text_run;62 struct fcft_text_run *placeholder_text_run;6364 /* Cached selection corners */65 pixman_image_t *selection_corners;6667 float scale;68 float dpi;69 bool size_font_by_dpi;70
14 unmodified lines
85 unsigned y_margin;86 unsigned inner_pad;87 unsigned border_size;88 unsigned border_radius;89 unsigned selection_border_radius;90 unsigned row_height;91 unsigned icon_height;9293 unsigned input_glyph_offset; /* At which glyph to start rendering input */
99 unmodified lines
193 fill_region32(op, dest, color, &region);194 pixman_region32_fini(&region);195}196193void194render_background(const struct render *render, struct buffer *buf)197static void198render_rounded_rectangle(pixman_image_t* dest, pixman_color_t* background,199 pixman_color_t* border, unsigned int radius, unsigned bw,200 int16_t x, int16_t y, uint16_t width, uint16_t height)201{196 unsigned bw = render->border_size;197198 pixman_color_t bg = render->pix_background_color;199 pixman_color_t border_color = render->pix_border_color;200201 if (buf->age == 0) {202 /* Each sub-part of the window erases itself */203 return;204 }205206 /* Limit radius if the margins are very small, to prevent e.g. the207 selection "box" from overlapping the corners */208 const unsigned int radius =209 min(render->border_radius,210 max(render->x_margin,211 render->y_margin));212202 if (radius == 0) {203 pixman_image_fill_rectangles(215 PIXMAN_OP_SRC, buf->pix[0], &bg,204 PIXMAN_OP_SRC, dest, background,205 1, &(pixman_rectangle16_t){217 bw, bw, buf->width - 2 * bw, buf->height - 2 * bw});206 x + bw, y + bw, width - 2 * bw, height - 2 * bw});207208 pixman_image_fill_rectangles(220 PIXMAN_OP_SRC, buf->pix[0], &border_color,209 PIXMAN_OP_SRC, dest, border,210 4, (pixman_rectangle16_t[]){222 {0, 0, buf->width, bw}, /* top */223 {0, bw, bw, buf->height - 2 * bw}, /* left */224 {buf->width - bw, bw, bw, buf->height - 2 * bw}, /* right */225 {0, buf->height - bw, buf->width, bw} /* bottom */211 {x, y, width, bw}, /* top */212 {x, y + bw, bw, height - 2 * bw}, /* left */213 {x + width - bw, y + bw, bw, height - 2 * bw}, /* right */214 {x, y + height - bw, width, bw} /* bottom */215 });216 } else {217 const int msaa_scale = 2;218 const double brd_sz_scaled = bw * msaa_scale;219 const double brd_rad_scaled = radius * msaa_scale;231 int w = buf->width * msaa_scale;232 int h = buf->height * msaa_scale;220 int w = width * msaa_scale;221 int h = height * msaa_scale;222 int bg_rad = brd_rad_scaled * (1.0 - (float)brd_sz_scaled / (float)brd_rad_scaled);223224 pixman_image_t *bg_img;236 if (msaa_scale != 1){225 if (msaa_scale != 1) {226 bg_img = pixman_image_create_bits(238 pixman_image_get_format(buf->pix[0]), w, h, NULL, w*4);227 pixman_image_get_format(dest), w, h, NULL, w*4);228 } else {240 bg_img = buf->pix[0];229 bg_img = dest;230 }231232 /* Border */233 fill_rounded_rectangle(245 PIXMAN_OP_SRC, bg_img, &border_color, 0, 0, w, h, brd_rad_scaled);234 PIXMAN_OP_SRC, bg_img, border, 0, 0, w, h, brd_rad_scaled);235236 /* Background */237 fill_rounded_rectangle(249 PIXMAN_OP_SRC, bg_img, &bg, brd_sz_scaled, brd_sz_scaled,238 PIXMAN_OP_SRC, bg_img, background, brd_sz_scaled, brd_sz_scaled,239 w-(brd_sz_scaled*2),240 h-(brd_sz_scaled*2),241 bg_rad);242254 if (msaa_scale != 1){243 if (msaa_scale != 1) {244 pixman_f_transform_t ftrans;245 pixman_transform_t trans;246 pixman_f_transform_init_scale(&ftrans, msaa_scale, msaa_scale);247 pixman_transform_from_pixman_f_transform(&trans, &ftrans);248 pixman_image_set_transform(bg_img, &trans);249 pixman_image_set_filter(bg_img, PIXMAN_FILTER_BILINEAR, NULL, 0);250251 pixman_image_composite32(263 PIXMAN_OP_SRC, bg_img, NULL, buf->pix[0], 0, 0, 0, 0, 0, 0,264 buf->width, buf->height);252 PIXMAN_OP_OVER, bg_img, NULL, dest, 0, 0, 0, 0, x, y,253 width, height);254 pixman_image_unref(bg_img);255 }256 }257}258259void260render_background(const struct render *render, struct buffer *buf)261{262 unsigned bw = render->border_size;263264 pixman_color_t bg = render->pix_background_color;265 pixman_color_t border_color = render->pix_border_color;266267 if (buf->age == 0) {268 /* Each sub-part of the window erases itself */269 return;270 }271272 /* Limit radius if the margins are very small, to prevent e.g. the273 selection "box" from overlapping the corners */274 const unsigned int radius =275 min(render->border_radius,276 max(render->x_margin,277 render->y_margin));278279 render_rounded_rectangle(buf->pix[0], &bg, &border_color, radius, bw,280 0, 0, buf->width, buf->height);281}282283static void284render_glyph(pixman_image_t *pix, const struct fcft_glyph *glyph, int x, int y,285 const pixman_color_t *color)286{
1044 unmodified lines
1331 PIXMAN_OP_SRC, pix, &bg, 1, &(pixman_rectangle16_t){x, y, w, h});1332}13331334static void1322render_selected_match_entry_background(const struct render *render,1335render_selected_match_entry_background(struct render *render,1336 int idx, pixman_image_t *pix, int width)1337{1338 pixman_color_t bg = render->pix_selection_color;1339
3 unmodified lines
1343 const int y = first_row_y(render) + idx * render->row_height;1344 const int w = width - 2 * (render->border_size + render->x_margin - sel_margin);1345 const int h = 1 * render->row_height;13461334 pixman_image_fill_rectangles(1335 PIXMAN_OP_OVER, pix, &bg, 1, &(pixman_rectangle16_t){x, y, w, h});1347 // limit radius to half of height, any larger and it causes weird shapes1348 // also limit it when horizontal padding is small, to prevent icon pop out1349 const unsigned int radius = min(1350 min(render->selection_border_radius, h / 2), render->x_margin);13511352 if (render->selection_corners == NULL) {1353 render->selection_corners = pixman_image_create_bits(1354 pixman_image_get_format(pix), w, h, NULL, w * 4);1355 render_rounded_rectangle(render->selection_corners, &bg, &bg, radius, 0, 0, 0, w, h);1356 }1357 pixman_image_composite(1358 PIXMAN_OP_OVER, render->selection_corners, NULL, pix,1359 0, 0, 0, 0, x, y, w, h);1360}13611362static void1339render_one_match_entry(const struct render *render, const struct matches *matches,1363render_one_match_entry(struct render *render, const struct matches *matches,1364 const struct match *match, bool render_icons,1365 int idx, bool is_selected, int width, int height,1366 pixman_image_t *pix, cairo_t *cairo)1367{
354 unmodified lines
1722 : 0;17231724 const unsigned border_size = render->conf->border.size * scale;1725 const unsigned border_radius = render->conf->border.radius * scale;1726 const unsigned selection_border_radius = render->conf->selection_border.radius * scale;17271728 const unsigned row_height = render->conf->line_height.px >= 01729 ? pt_or_px_as_pixels(render, &render->conf->line_height)1730 : max(font->height, font->ascent + font->descent);
28 unmodified lines
1759 render->x_margin = x_margin;1760 render->inner_pad = inner_pad;1761 render->border_size = border_size;1762 render->border_radius = border_radius;1763 render->selection_border_radius = selection_border_radius;1764 render->row_height = row_height;1765 render->icon_height = icon_height;17661767 if (new_width != NULL)1768 *new_width = width;1769 if (new_height != NULL)1770 *new_height = height;17711772 /* invalidate cached corners since the size could have changed */1773 if (render->selection_corners != NULL) {1774 pixman_image_unref(render->selection_corners);1775 render->selection_corners = NULL;1776 }1777}17781779bool1780render_set_font_and_update_sizes(struct render *render, struct fcft_font *font,
63 unmodified lines
18441845 fcft_text_run_destroy(render->prompt_text_run);1846 fcft_text_run_destroy(render->placeholder_text_run);18471848 pixman_image_unref(render->selection_corners);18491850 fcft_destroy(render->font);1851 fcft_destroy(render->font_bold);1852 free(render);1853}
36 unmodified lines