diff --git a/README.md b/README.md index 0127be0..57a1210 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/) ### Changelog: -2020-08-05 - Added the grid and dynamic options patches +2020-08-05 - Added the grid, dynamic options and numbers patches 2020-06-13 - Added the pango patch @@ -88,6 +88,9 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/) - this means that you can continue feeding dmenu while you type - the patch is meant to be used along with the incremental patch in order to use stdout to feed stdin + - [numbers](https://tools.suckless.org/dmenu/patches/numbers/) + - adds text which displays the number of matched and total items in the top right corner of dmenu + - [pango](https://github.com/StillANixRookie/dmenu-pango/) - adds simple markup for dmenu using pango markup diff --git a/dmenu.c b/dmenu.c index 2c7acea..4be2bef 100644 --- a/dmenu.c +++ b/dmenu.c @@ -249,7 +249,7 @@ drawmenu(void) unsigned int curpos; #endif // SCROLL_PATCH struct item *item; - int x = 0, y = 0, w; + int x = 0, y = 0, w, rpad = 0; #if LINE_HEIGHT_PATCH && PANGO_PATCH int fh = drw->font->h; #elif LINE_HEIGHT_PATCH @@ -340,6 +340,10 @@ drawmenu(void) } #endif // SCROLL_PATCH + #if NUMBERS_PATCH + recalculatenumbers(); + rpad = TEXTW(numbers); + #endif // NUMBERS_PATCH if (lines > 0) { #if GRID_PATCH /* draw grid */ @@ -391,20 +395,25 @@ drawmenu(void) x += w; for (item = curr; item != next; item = item->right) #if PANGO_PATCH - x = drawitem(item, x, 0, MIN(TEXTWM(item->text), mw - x - TEXTW(">"))); + x = drawitem(item, x, 0, MIN(TEXTWM(item->text), mw - x - TEXTW(">") - rpad)); #else - x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); + x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - rpad)); #endif // PANGO_PATCH if (next) { w = TEXTW(">"); drw_setscheme(drw, scheme[SchemeNorm]); #if PANGO_PATCH - drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0, True); + drw_text(drw, mw - w - rpad, 0, w, bh, lrpad / 2, ">", 0, True); #else - drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); + drw_text(drw, mw - w - rpad, 0, w, bh, lrpad / 2, ">", 0); #endif // PANGO_PATCH } } + #if NUMBERS_PATCH + drw_setscheme(drw, scheme[SchemeNorm]); + drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0); + #else + #endif // NUMBERS_PATCH drw_map(drw, win, 0, 0, mw, mh); #if NON_BLOCKING_STDIN_PATCH XFlush(dpy); diff --git a/patch/include.c b/patch/include.c index 608d71a..b6b054d 100644 --- a/patch/include.c +++ b/patch/include.c @@ -19,6 +19,9 @@ #if NON_BLOCKING_STDIN_PATCH #include "nonblockingstdin.c" #endif +#if NUMBERS_PATCH +#include "numbers.c" +#endif #if XRESOURCES_PATCH #include "xresources.c" #endif \ No newline at end of file diff --git a/patch/include.h b/patch/include.h index 311cb1e..5928366 100644 --- a/patch/include.h +++ b/patch/include.h @@ -3,4 +3,7 @@ #endif #if NON_BLOCKING_STDIN_PATCH #include "nonblockingstdin.h" +#endif +#if NUMBERS_PATCH +#include "numbers.h" #endif \ No newline at end of file diff --git a/patch/numbers.c b/patch/numbers.c new file mode 100644 index 0000000..9f9557a --- /dev/null +++ b/patch/numbers.c @@ -0,0 +1,16 @@ +static char numbers[NUMBERSBUFSIZE] = ""; + +static void +recalculatenumbers() +{ + unsigned int numer = 0, denom = 0; + struct item *item; + if (matchend) { + numer++; + for (item = matchend; item && item->left; item = item->left) + numer++; + } + for (item = items; item && item->text; item++) + denom++; + snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom); +} \ No newline at end of file diff --git a/patch/numbers.h b/patch/numbers.h new file mode 100644 index 0000000..34d3dbc --- /dev/null +++ b/patch/numbers.h @@ -0,0 +1,4 @@ +#define NUMBERSMAXDIGITS 100 +#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 + +static void recalculatenumbers(); \ No newline at end of file diff --git a/patches.def.h b/patches.def.h index 25ec59a..b70ff79 100644 --- a/patches.def.h +++ b/patches.def.h @@ -97,6 +97,11 @@ */ #define NON_BLOCKING_STDIN_PATCH 0 +/* Adds text which displays the number of matched and total items in the top right corner of dmenu. + * https://tools.suckless.org/dmenu/patches/numbers/ + */ +#define NUMBERS_PATCH 0 + /* This patch adds simple markup for dmenu using pango markup. * This depends on the pango library v1.44 or greater. * You need to uncomment the corresponding lines in config.mk to use the pango libraries