dmenu

Mahdi's build of dmenu
git clone git://mahdi.pw/dmenu.git
Log | Files | Refs | README | LICENSE

commit 593a1208fe956979c7aefda4bcea44a1da879235
parent 9aee149e34532922d09c7a0f8fdfd16b8d6ee358
Author: Mahdi Mirzade <[email protected]>
Date:   Thu, 13 Oct 2022 07:39:33 +0330

add numbers patch to dmenu

Diffstat:
Mdmenu.c | 27++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/dmenu.c b/dmenu.c @@ -28,6 +28,8 @@ * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) #define LENGTH(X) (sizeof X / sizeof X[0]) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) +#define NUMBERSMAXDIGITS 100 +#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 #define OPAQUE 0xffU @@ -39,6 +41,7 @@ struct item { int out; }; +static char numbers[NUMBERSBUFSIZE] = ""; static char text[BUFSIZ] = ""; static char fribidi_text[BUFSIZ] = ""; static char *embed; @@ -113,7 +116,7 @@ calcoffsets(void) if (lines > 0) n = lines * bh; else - n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); + n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">") + TEXTW(numbers)); /* calculate which items will begin the next page and previous page */ for (i = 0, next = curr; next; next = next->right) if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)) > n) @@ -230,6 +233,21 @@ drawitem(struct item *item, int x, int y, int w) } 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); +} + +static void drawmenu(void) { unsigned int curpos; @@ -263,6 +281,7 @@ drawmenu(void) drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); } + recalculatenumbers(); if (lines > 0) { /* draw vertical list */ for (item = curr; item != next; item = item->right) @@ -277,13 +296,15 @@ drawmenu(void) } x += w; for (item = curr; item != next; item = item->right) - x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">"))); + x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">") - TEXTW(numbers))); if (next) { w = TEXTW(">"); drw_setscheme(drw, scheme[SchemeNorm]); - drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); + drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0); } } + drw_setscheme(drw, scheme[SchemeNorm]); + drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0); drw_map(drw, win, 0, 0, mw, mh); }