dmenu

my fork of dmenu
Index Commits Files Refs README LICENSE
patches/dmenu-numbers-4.9.diff (2393B)
   1 From 61abc60dbfaa8ec63fcd176307308aee88a19e32 Mon Sep 17 00:00:00 2001
   2 From: Miles Alan <m@milesalan.com>
   3 Date: Sat, 10 Aug 2019 17:20:08 -0500
   4 Subject: [PATCH] Display number of matched and total items in top right corner
   5 
   6 ---
   7  dmenu.c | 25 +++++++++++++++++++++++--
   8  1 file changed, 23 insertions(+), 2 deletions(-)
   9 
  10 diff --git a/dmenu.c b/dmenu.c
  11 index 6b8f51b..98c5810 100644
  12 --- a/dmenu.c
  13 +++ b/dmenu.c
  14 @@ -24,6 +24,8 @@
  15                               * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
  16  #define LENGTH(X)             (sizeof X / sizeof X[0])
  17  #define TEXTW(X)              (drw_fontset_getwidth(drw, (X)) + lrpad)
  18 +#define NUMBERSMAXDIGITS      100
  19 +#define NUMBERSBUFSIZE        (NUMBERSMAXDIGITS * 2) + 1
  20  
  21  /* enums */
  22  enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
  23 @@ -34,6 +36,7 @@ struct item {
  24      int out;
  25  };
  26  
  27 +static char numbers[NUMBERSBUFSIZE] = "";
  28  static char text[BUFSIZ] = "";
  29  static char *embed;
  30  static int bh, mw, mh;
  31 @@ -126,6 +129,21 @@ drawitem(struct item *item, int x, int y, int w)
  32      return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
  33  }
  34  
  35 +static void
  36 +recalculatenumbers()
  37 +{
  38 +    unsigned int numer = 0, denom = 0;
  39 +    struct item *item;
  40 +    if (matchend) {
  41 +        numer++;
  42 +        for (item = matchend; item && item->left; item = item->left)
  43 +            numer++;
  44 +    }
  45 +    for (item = items; item && item->text; item++)
  46 +        denom++;
  47 +    snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
  48 +}
  49 +
  50  static void
  51  drawmenu(void)
  52  {
  53 @@ -151,6 +169,7 @@ drawmenu(void)
  54          drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
  55      }
  56  
  57 +    recalculatenumbers();
  58      if (lines > 0) {
  59          /* draw vertical list */
  60          for (item = curr; item != next; item = item->right)
  61 @@ -165,13 +184,15 @@ drawmenu(void)
  62          }
  63          x += w;
  64          for (item = curr; item != next; item = item->right)
  65 -            x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
  66 +            x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
  67          if (next) {
  68              w = TEXTW(">");
  69              drw_setscheme(drw, scheme[SchemeNorm]);
  70 -            drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
  71 +            drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
  72          }
  73      }
  74 +    drw_setscheme(drw, scheme[SchemeNorm]);
  75 +    drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
  76      drw_map(drw, win, 0, 0, mw, mh);
  77  }
  78  
  79 -- 
  80 2.19.2
  81