Adding numbers patch

This commit is contained in:
bakkeby 2020-08-05 12:40:03 +02:00
parent 73d2405635
commit 768b5527ab
7 changed files with 49 additions and 6 deletions

View File

@ -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

19
dmenu.c
View File

@ -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);

View File

@ -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

View File

@ -4,3 +4,6 @@
#if NON_BLOCKING_STDIN_PATCH
#include "nonblockingstdin.h"
#endif
#if NUMBERS_PATCH
#include "numbers.h"
#endif

16
patch/numbers.c Normal file
View File

@ -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);
}

4
patch/numbers.h Normal file
View File

@ -0,0 +1,4 @@
#define NUMBERSMAXDIGITS 100
#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
static void recalculatenumbers();

View File

@ -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