~smlavine/dmenu

90977b8702f05c44159eb00f928bc497f286ce53 — Sebastian LaVine 5 months ago 86b3af3
Revert "Revert "Apply dmenu-numbers-4.9.diff""

This reverts commit c00b82d8ba0586c0b60bd84cd6eafc3df8bb704d.
1 files changed, 23 insertions(+), 2 deletions(-)

M dmenu.c
M dmenu.c => dmenu.c +23 -2
@@ 25,6 25,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

/* enums */
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */


@@ 34,6 36,7 @@ struct item {
	int out;
};

static char numbers[NUMBERSBUFSIZE] = "";
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;


@@ 178,6 181,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;


@@ 202,6 220,7 @@ drawmenu(void)
		drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
	}

	recalculatenumbers();
	if (lines > 0) {
		/* draw grid */
		int i = 0;


@@ 222,13 241,15 @@ drawmenu(void)
		}
		x += w;
		for (item = curr; item != next; item = item->right)
			x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
			x = drawitem(item, x, 0, MIN(TEXTW(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);
}