Skip to content
Myr

Add new --minimal-flag option

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

Useful for building small dmenu menus with a dynamic number of lines that's less than --lines. Fuzzel prevents displaying anything until all dmenu entries have been loaded, at which point the number of display lines to use are calculated (the minimum of --lines, and the total number of dmenu entries).

authored by Mark Stosberg · committed by Daniel Eklöf · parent 63cd8ea · Browse files · 13 files+120 added−34 removed
This commit

State

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

Trailers

  • Co-authored-by: Daniel Eklöf <daniel@ekloef.se>

Diff stats

13 files+120 added−34 removed

  • other:+120 added−34 removed

13 files+120 added−34 removed

modified:completions/fish/fuzzel.fish+1 added
35 unmodified lines
36complete -c fuzzel -x -l y-margin -d "vertical margin away from the anchor point in pixels (0)"37complete -c fuzzel -x -l select -d "select the first entry that matches the given string"38complete -c fuzzel -x -l select-index -d "select the entry at index"39complete -c fuzzel -x -s l -l lines -d "maximum number of matches to displayh (15)"40complete -c fuzzel -l minimal-lines -d "adjust lines to minimum of --lines and input lines (dmenu mode only)"41complete -c fuzzel -x -s w -l width -d "window width, in characters (30)"42complete -c fuzzel -x -s x -l horizontal-pad -d "horizontal padding, in pixels (40)"43complete -c fuzzel -x -s y -l vertical-pad -d "vertical padding, in pixels (8)"44complete -c fuzzel -x -s P -l inner-pad -d "vertical padding between prompt and matches, in pixels (0)"
44 unmodified lines
modified:completions/zsh/_fuzzel+1 added
27 unmodified lines
28 '--y-margin[vertical margin away from the anchor point in pixels (0)]:()' \29 '--select[select the first entry that matches the given string]:()' \30 '--select-index[select the entry with index]:()' \31 '(-l --lines)'{-l,--lines}'[maximum number of matches to display (15)]:()' \32 '--minimal-lines[adjust lines to minimum of --lines and input lines (dmenu mode only)]' \33 '(-w --width)'{-w,--width}'[window width, in characters (30)]:()' \34 '(-x --horizontal-pad)'{-x,--horizontal-pad}'[horizontal padding, in pixels (40)]:()' \35 '(-y --vertical-pad)'{-y,--vertical-pad}'[vertical padding, in pixels (8)]:()' \36 '(-P --inner-pad)'{-P,--inner-pad}'[vertical padding between prompt and matches, in pixels (0)]:()' \
62 unmodified lines
modified:doc/fuzzel.1.scd+6 added
216 unmodified lines
217*-l*,*--lines*=COUNT218 The (maximum) number of matches to display. This dictates the219 window height. Default: _15_.220221*--minimal-lines*222 Adjust the number of lines to display to the minimum of _--lines_ and223 the number of input lines. Only effective in dmenu mode. This allows224 fuzzel to size itself to the actual number of input lines rather than225 always showing the full _--lines_ rows.226227*-w*,*--width*228 Window width, in characters. Margins and borders not included. For229 variable width fonts this is an estimate, as the exact number of230 characters that will fit depends on which characters are being
335 unmodified lines
modified:doc/fuzzel.ini.5.scd+7 added
267 unmodified lines
268269*lines*270 Number of matches to show. Default: _15_.271272*minimal-lines*273 Boolean. Adjust the number of lines to display to the minimum of274 _lines_ and the number of input lines. Only effective in dmenu275 mode. This allows fuzzel to size itself to the actual number of276 input lines rather than always showing the full _lines_277 rows. Default: _no_.278279*width*280 Window width, in characters. Margins and borders not included. For281 variable width fonts this is an estimate, as the exact number of282 characters that will fit depends on which characters are being
393 unmodified lines
modified:CHANGELOG.md+4 added
42 unmodified lines
43 ([#546][546]).44* `scaling-filter` option (and the corresponding `--scaling-filter`45 command line option). This option defines which scaling filter46 fuzzel uses when down scaling PNGs ([#553][553]).47* `--minimal-lines` command line and config option, causing fuzzel to48 adjust the number of displayed lines to the minimum of `--lines` and49 the number of input lines ([#144][144])5051[504]: https://codeberg.org/dnkl/fuzzel/pulls/50452[512]: https://codeberg.org/dnkl/fuzzel/pulls/51253[546]: https://codeberg.org/dnkl/fuzzel/issues/54654[553]: https://codeberg.org/dnkl/fuzzel/issues/55355[144]: https://codeberg.org/dnkl/fuzzel/issues/144565758### Changed59
954 unmodified lines
modified:config.c+3 added
947 unmodified lines
948949 else if (strcmp(key, "lines") == 0)950 return value_to_uint32(ctx, 10, &conf->lines);951952 else if (strcmp(key, "minimal-lines") == 0)953 return value_to_bool(ctx, &conf->minimal_lines);954955 else if (strcmp(key, "width") == 0)956 return value_to_uint32(ctx, 10, &conf->chars);957958 else if (strcmp(key, "tabs") == 0)
813 unmodified lines
modified:config.h+1 added
175 unmodified lines
176 unsigned y;177 } margin;178179 unsigned lines;180 bool minimal_lines;181 unsigned chars;182 unsigned tabs; /* Tab stop every number of #spaces */183184 struct {
49 unmodified lines
modified:fuzzel.ini+1 added
22 unmodified lines
23# anchor=center24# x-margin=025# y-margin=026# lines=1527# minimal-lines=no28# width=3029# tabs=830# horizontal-pad=4031# vertical-pad=8
89 unmodified lines
modified:main.c+44 added-4 removed
41 unmodified lines
42#include "xmalloc.h"43#include "xsnprintf.h"4445#define max(x, y) ((x) > (y) ? (x) : (y))46#define min(x, y) ((x) < (y) ? (x) : (y))4748struct context {48 const struct config *conf;49 struct config *conf;50 const char *cache_path;51 struct wayland *wayl;52 struct render *render;53 struct matches *matches;
318 unmodified lines
372 " --select=STRING select first entry that matches the given\n"373 " string\n"374 " --select-index=INDEX select the entry with index, not compatible with --select\n"375 " -l,--lines number of matches to show\n"376 " --minimal-lines adjust the number of lines to the\n"377 " minimum of --lines and the number\n"378 " of input lines (dmenu mode only)\n"379 " -w,--width window width, in characters (margins and\n"380 " borders not included)\n"381 " --tabs=INT number of spaces a tab is expanded to (8)\n"382 " -x,--horizontal-pad=PAD horizontal padding, in pixels (40)\n"
273 unmodified lines
656657 if (event == EVENT_APPS_ALL_LOADED) {658 if (conf->dmenu.exit_immediately_if_empty && apps->count == 0)659 return false;660661 matches_all_applications_loaded(matches);662663 if (conf->dmenu.enabled && conf->minimal_lines) {664 const size_t effective_lines = min(apps->count, conf->lines);665 matches_max_matches_per_page_set(matches, effective_lines);666 ctx->conf->lines = effective_lines;667 wayl_resized(wayl);668 }669670 wayl_ready_to_display(wayl);671 }672673 const size_t match_count = matches_get_count(matches);
17 unmodified lines
691 }692 }693 else694 matches_selected_select(matches, select);695 }696683 if (!conf->dmenu.exit_immediately_if_empty)684 wayl_ready_to_display(wayl);697 /*698 * Allow displaying the menu if:699 * --no-run-if-empty is NOT enabled, OR we have at least one entry700 * AND701 * --minimal-lines is NOT enabled, OR we have at least --lines number of entries702 *703 * In short, display the window as soon as we are sure we704 * won't exit automatically (due to --no-run-if-empty), and we705 * know its final size.706 */707 if ((!conf->dmenu.exit_immediately_if_empty || apps->count > 0) &&708 (!(conf->dmenu.enabled && conf->minimal_lines) ||709 apps->count >= conf->lines))710 {711 wayl_ready_to_display(wayl);712 }713 break;714 }715
117 unmodified lines
833 #define OPT_DMENU_ACCEPT_NTH 299834 #define OPT_GAMMA_CORRECT 300835 #define OPT_PRINT_TIMINGS 301836 #define OPT_SCALING_FILTER 302837 #define OPT_MINIMAL_LINES 303838839 static const struct option longopts[] = {840 {"config", required_argument, 0, OPT_CONFIG},841 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},
14 unmodified lines
856 {"y-margin", required_argument, 0, OPT_Y_MARGIN},857 {"select", required_argument, 0, OPT_SELECT},858 {"select-index", required_argument, 0, OPT_SELECT_INDEX},859 {"lines", required_argument, 0, 'l'},860 {"minimal-lines", no_argument, 0, OPT_MINIMAL_LINES},861 {"width", required_argument, 0, 'w'},862 {"tabs", required_argument, 0, OPT_TABS},863 {"horizontal-pad", required_argument, 0, 'x'},864 {"vertical-pad", required_argument, 0, 'y'},
74 unmodified lines
939 bool anchor_set:1;940 bool x_margin_set : 1;941 bool y_margin_set : 1;942 bool lines_set:1;943 bool minimal_lines_set:1;944 bool chars_set:1;945 bool tabs_set:1;946 bool pad_x_set:1;947 bool pad_y_set:1;
275 unmodified lines
1223 }1224 cmdline_overrides.lines_set = true;1225 break;12261227 case OPT_MINIMAL_LINES:1228 cmdline_overrides.conf.minimal_lines = true;1229 cmdline_overrides.minimal_lines_set = true;1230 break;12311232 case 'w':1233 if (sscanf(optarg, "%u", &cmdline_overrides.conf.chars) != 1) {1234 fprintf(stderr, "%s: invalid width\n", optarg);1235 return EXIT_FAILURE;
683 unmodified lines
1919 if (cmdline_overrides.y_margin_set)1920 conf.margin.y = cmdline_overrides.conf.margin.y;1921 if (cmdline_overrides.lines_set)1922 conf.lines = cmdline_overrides.conf.lines;1923 if (cmdline_overrides.minimal_lines_set)1924 conf.minimal_lines = cmdline_overrides.conf.minimal_lines;1925 if (cmdline_overrides.chars_set)1926 conf.chars = cmdline_overrides.conf.chars;1927 if (cmdline_overrides.tabs_set)1928 conf.tabs = cmdline_overrides.conf.tabs;
224 unmodified lines
2153 }21542155 join_app_thread = true;21562120 if (!(conf.dmenu.exit_immediately_if_empty))2157 if (!conf.dmenu.exit_immediately_if_empty &&2158 !(conf.dmenu.enabled && conf.minimal_lines))2159 {2160 wayl_ready_to_display(wayl);2161 }21622163 wayl_refresh(wayl);21642165 while (true) {
68 unmodified lines
modified:render.c+37 added-26 removed
1337 unmodified lines
1338 assert(tll_length(render->workers.queue) == 0);1339 }13401341 /* Erase background of the "empty" area, after the last match */1342 const size_t effective_lines = matches_max_matches_per_page(matches);1343 render_match_entry_background(1343 render, match_count, render->conf->lines - match_count,1344 render, match_count, effective_lines - match_count,1345 buf->pix[0], buf->width);13461347 for (size_t i = 0; i < match_count; i++) {1348 if (render->workers.count == 0) {
181 unmodified lines
1530 render->pix_counter_color = rgba2pixman(gamma_correct, conf->colors.counter);1531 render->pix_placeholder_color = rgba2pixman(gamma_correct, conf->colors.placeholder);1532}153315331534void1535render_set_subpixel(struct render *render, enum fcft_subpixel subpixel)1536{1537 render->subpixel = subpixel;1538}15391540bool1541render_set_font_and_update_sizes(struct render *render, struct fcft_font *font,1542 struct fcft_font *font_bold,1543 float scale, float dpi, bool size_font_by_dpi,1544 int *new_width, int *new_height)1540void1541render_resized(struct render *render, int *new_width, int *new_height)1542{1546 if (font != NULL) {1547 fcft_destroy(render->font);1548 render->font = font;1549 } else {1550 assert(render->font != NULL);1551 font = render->font;1552 }1543 struct fcft_font *font = render->font;1544 const float scale = render->scale;15451554 if (font_bold != NULL) {1555 fcft_destroy(render->font_bold);1556 render->font_bold = font_bold;1557 } else {1558 assert(render->font_bold != NULL);1559 font_bold = render->font_bold;1560 }1546 assert(font != NULL);1547 assert(render->font_bold != NULL);15481562 render->scale = scale;1563 render->dpi = dpi;1564 render->size_font_by_dpi = size_font_by_dpi;15651549 const struct fcft_glyph *W = fcft_rasterize_char_utf32(1550 font, U'o', render->subpixel);15511552 const unsigned x_margin = render->conf->pad.x * scale;
19 unmodified lines
1572 y_margin +1573 border_size; /* Bottom border */15741575 const unsigned width =1593 border_size +1576 border_size + /* Top border */1577 x_margin +1578 (max((W->advance.x + pt_or_px_as_pixels(1579 render, &render->conf->letter_spacing)),1580 0)
16 unmodified lines
1597 if (new_width != NULL)1598 *new_width = width;1599 if (new_height != NULL)1600 *new_height = height;1601}16021603bool1604render_set_font_and_update_sizes(struct render *render, struct fcft_font *font,1605 struct fcft_font *font_bold,1606 float scale, float dpi, bool size_font_by_dpi,1607 int *new_width, int *new_height)1608{1609 if (font != NULL) {1610 fcft_destroy(render->font);1611 render->font = font;1612 } else {1613 assert(render->font != NULL);1614 font = render->font;1615 }16161617 if (font_bold != NULL) {1618 fcft_destroy(render->font_bold);1619 render->font_bold = font_bold;1620 } else {1621 assert(render->font_bold != NULL);1622 font_bold = render->font_bold;1623 }16241625 render->scale = scale;1626 render->dpi = dpi;1627 render->size_font_by_dpi = size_font_by_dpi;16281629 render_resized(render, new_width, new_height);1630 return true;1631}16321633int
74 unmodified lines
modified:render.h+1 added
20 unmodified lines
21bool render_set_font_and_update_sizes(22 struct render *render, struct fcft_font *font, struct fcft_font *font_bold,23 float scale, float dpi, bool size_font_by_dpi,24 int *new_width, int *new_height);25void render_resized(struct render *render, int *new_width, int *new_height);26void render_flush_text_run_cache(struct render *render);2728void render_background(const struct render *render, struct buffer *buf);29
13 unmodified lines
modified:wayland.c+12 added-4 removed
1427 unmodified lines
14281429 wayl->scale = scale;1430 wayl->dpi = dpi;14311432 wayl_resized(wayl);1433}14341435void1436wayl_resized(struct wayland *wayl)1437{1438 render_resized(wayl->render, &wayl->width, &wayl->height);14391440 const float scale = wayl->scale;14411442 wayl->width = roundf(roundf(wayl->width / scale) * scale);1443 wayl->height = roundf(roundf(wayl->height / scale) * scale);14441445 zwlr_layer_surface_v1_set_size(
6 unmodified lines
1452 wayl->conf->margin.y, wayl->conf->margin.x);14531454 zwlr_layer_surface_v1_set_anchor(1455 wayl->layer_surface, wayl->conf->anchor);14461447 /* Trigger a 'configure' event, after which we'll have the actual width+height */1448 wl_surface_commit(wayl->surface);1449 wl_display_roundtrip(wayl->display);1456}14571458static void1459output_update_ppi(struct monitor *mon)
1162 unmodified lines
26222623 wayl->subpixel = wayl->monitor != NULL2624 ? (enum fcft_subpixel)wayl->monitor->subpixel : guess_subpixel(wayl);2625 update_size(wayl);2626 wl_surface_commit(wayl->surface);2627 wl_display_roundtrip(wayl->display);26282629 if (wl_display_prepare_read(wayl->display) != 0) {2630 LOG_ERRNO("failed to prepare for reading wayland events");2631 goto out;
173 unmodified lines
modified:wayland.h+2 added
87 unmodified lines
88void wayl_clipboard_data(struct wayland *wayl, char *data, size_t size);89void wayl_clipboard_done(struct wayland *wayl);9091bool wayl_do_linear_blending(const struct wayland *wayl);9293void wayl_resized(struct wayland *wayl);