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
Provenance
- Commit
6200008- Tree
c3ec867- Author
Mark Stosberg <mark@stosberg.com>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
63cd8ea
13 files changed+120 added−34 removed
modified:completions/fish/fuzzel.fish+1 added
35 unmodified lines36 complete -c fuzzel -x -l y-margin -d "vertical margin away from the anchor point in pixels (0)"37 complete -c fuzzel -x -l select -d "select the first entry that matches the given string"38 complete -c fuzzel -x -l select-index -d "select the entry at index"39 complete -c fuzzel -x -s l -l lines -d "maximum number of matches to displayh (15)"40+complete -c fuzzel -l minimal-lines -d "adjust lines to minimum of --lines and input lines (dmenu mode only)"41 complete -c fuzzel -x -s w -l width -d "window width, in characters (30)"42 complete -c fuzzel -x -s x -l horizontal-pad -d "horizontal padding, in pixels (40)"43 complete -c fuzzel -x -s y -l vertical-pad -d "vertical padding, in pixels (8)"44 complete -c fuzzel -x -s P -l inner-pad -d "vertical padding between prompt and matches, in pixels (0)"44 unmodified linesmodified:completions/zsh/_fuzzel+1 added
27 unmodified lines28 '--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 linesmodified:doc/fuzzel.1.scd+6 added
216 unmodified lines217 *-l*,*--lines*=COUNT218 The (maximum) number of matches to display. This dictates the219 window height. Default: _15_.220 221+*--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.226+227 *-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 being335 unmodified linesmodified:doc/fuzzel.ini.5.scd+7 added
267 unmodified lines268 269 *lines*270 Number of matches to show. Default: _15_.271 272+*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_.278+279 *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 being393 unmodified linesmodified:CHANGELOG.md+4 added
42 unmodified lines43 ([#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])50 51 [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/14456 57 58 ### Changed59 954 unmodified linesmodified:config.c+3 added
947 unmodified lines948 949 else if (strcmp(key, "lines") == 0)950 return value_to_uint32(ctx, 10, &conf->lines);951 952+ else if (strcmp(key, "minimal-lines") == 0)953+ return value_to_bool(ctx, &conf->minimal_lines);954+955 else if (strcmp(key, "width") == 0)956 return value_to_uint32(ctx, 10, &conf->chars);957 958 else if (strcmp(key, "tabs") == 0)813 unmodified linesmodified:config.h+1 added
175 unmodified lines176 unsigned y;177 } margin;178 179 unsigned lines;180+ bool minimal_lines;181 unsigned chars;182 unsigned tabs; /* Tab stop every number of #spaces */183 184 struct {49 unmodified linesmodified:fuzzel.ini+1 added
22 unmodified lines23 # anchor=center24 # x-margin=025 # y-margin=026 # lines=1527+# minimal-lines=no28 # width=3029 # tabs=830 # horizontal-pad=4031 # vertical-pad=889 unmodified linesmodified:main.c+44 added-4 removed
41 unmodified lines42 #include "xmalloc.h"43 #include "xsnprintf.h"44 45 #define max(x, y) ((x) > (y) ? (x) : (y))46+#define min(x, y) ((x) < (y) ? (x) : (y))47 48 struct 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 lines372 " --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 lines656 657 if (event == EVENT_APPS_ALL_LOADED) {658 if (conf->dmenu.exit_immediately_if_empty && apps->count == 0)659 return false;660+661 matches_all_applications_loaded(matches);662+663+ 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+ }669+670 wayl_ready_to_display(wayl);671 }672 673 const size_t match_count = matches_get_count(matches);17 unmodified lines691 }692 }693 else694 matches_selected_select(matches, select);695+ }696 683- 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 lines833 #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 303838 839 static const struct option longopts[] = {840 {"config", required_argument, 0, OPT_CONFIG},841 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},14 unmodified lines856 {"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 lines939 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 lines1223 }1224 cmdline_overrides.lines_set = true;1225 break;1226 1227+ case OPT_MINIMAL_LINES:1228+ cmdline_overrides.conf.minimal_lines = true;1229+ cmdline_overrides.minimal_lines_set = true;1230+ break;1231+1232 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 lines1919 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 lines2153 }2154 2155 join_app_thread = true;2156 2120- 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+ }2162 2163 wayl_refresh(wayl);2164 2165 while (true) {68 unmodified linesmodified:render.c+37 added-26 removed
1337 unmodified lines1338 assert(tll_length(render->workers.queue) == 0);1339 }1340 1341 /* 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);1346 1347 for (size_t i = 0; i < match_count; i++) {1348 if (render->workers.count == 0) {181 unmodified lines1530 render->pix_counter_color = rgba2pixman(gamma_correct, conf->colors.counter);1531 render->pix_placeholder_color = rgba2pixman(gamma_correct, conf->colors.placeholder);1532 }1533 1533-1534 void1535 render_set_subpixel(struct render *render, enum fcft_subpixel subpixel)1536 {1537 render->subpixel = subpixel;1538 }1539 1540-bool1541-render_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)1540+void1541+render_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;1545 1554- 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);1548 1562- render->scale = scale;1563- render->dpi = dpi;1564- render->size_font_by_dpi = size_font_by_dpi;1565-1549 const struct fcft_glyph *W = fcft_rasterize_char_utf32(1550 font, U'o', render->subpixel);1551 1552 const unsigned x_margin = render->conf->pad.x * scale;19 unmodified lines1572 y_margin +1573 border_size; /* Bottom border */1574 1575 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 lines1597 if (new_width != NULL)1598 *new_width = width;1599 if (new_height != NULL)1600 *new_height = height;1601+}1602 1603+bool1604+render_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+ }1616+1617+ 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+ }1624+1625+ render->scale = scale;1626+ render->dpi = dpi;1627+ render->size_font_by_dpi = size_font_by_dpi;1628+1629+ render_resized(render, new_width, new_height);1630 return true;1631 }1632 1633 int74 unmodified linesmodified:render.h+1 added
20 unmodified lines21 bool 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);25+void render_resized(struct render *render, int *new_width, int *new_height);26 void render_flush_text_run_cache(struct render *render);27 28 void render_background(const struct render *render, struct buffer *buf);29 13 unmodified linesmodified:wayland.c+12 added-4 removed
1427 unmodified lines1428 1429 wayl->scale = scale;1430 wayl->dpi = dpi;1431 1432+ wayl_resized(wayl);1433+}1434+1435+void1436+wayl_resized(struct wayland *wayl)1437+{1438+ render_resized(wayl->render, &wayl->width, &wayl->height);1439+1440+ const float scale = wayl->scale;1441+1442 wayl->width = roundf(roundf(wayl->width / scale) * scale);1443 wayl->height = roundf(roundf(wayl->height / scale) * scale);1444 1445 zwlr_layer_surface_v1_set_size(6 unmodified lines1452 wayl->conf->margin.y, wayl->conf->margin.x);1453 1454 zwlr_layer_surface_v1_set_anchor(1455 wayl->layer_surface, wayl->conf->anchor);1446-1447- /* 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 }1457 1458 static void1459 output_update_ppi(struct monitor *mon)1162 unmodified lines2622 2623 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);2628 2629 if (wl_display_prepare_read(wayl->display) != 0) {2630 LOG_ERRNO("failed to prepare for reading wayland events");2631 goto out;173 unmodified linesmodified:wayland.h+2 added
87 unmodified lines88 void wayl_clipboard_data(struct wayland *wayl, char *data, size_t size);89 void wayl_clipboard_done(struct wayland *wayl);90 91 bool wayl_do_linear_blending(const struct wayland *wayl);92+93+void wayl_resized(struct wayland *wayl);