summaryrefslogtreecommitdiffstats
path: root/dmenu.c
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-03-06 00:24:26 -0500
committerMalfurious <m@lfurio.us>2024-03-06 00:55:08 -0500
commitd89df8faff5950b6176a8edc6db50e9f4be5167e (patch)
treed4b097ed5a879db09ad85c817d4e6eb1729878a5 /dmenu.c
parent63095a31b993ce1b9a2d4fcff5c61cce9defacd2 (diff)
downloaddmenu-master.tar.gz
dmenu-master.zip
patch: numbersHEADmaster
Adds text which displays the number of matched and total items in the top right corner of dmenu.
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/dmenu.c b/dmenu.c
index 617972c..2e17576 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -25,6 +25,8 @@
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define NUMBERSMAXDIGITS 100
+#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
#define OPAQUE 0xffu
@@ -37,6 +39,7 @@ struct item {
int out;
};
+static char numbers[NUMBERSBUFSIZE] = "";
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
@@ -95,7 +98,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)
@@ -153,6 +156,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;
@@ -177,6 +195,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)
@@ -191,13 +210,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);
}