Browse Source

apply numbers patch

master
krrishg 4 years ago
parent
commit
573f9da0b0
  1. 15
      config.def.h
  2. 11
      config.h
  3. BIN
      dmenu
  4. 25
      dmenu.c
  5. 3
      dmenu.c.orig
  6. BIN
      dmenu.o
  7. 81
      patches/dmenu-numbers-4.9.diff

15
config.def.h

@ -13,9 +13,18 @@ static const char *fonts[] = {
static const char *prompt = NULL; /* -p option; prompt to the left of input field */ static const char *prompt = NULL; /* -p option; prompt to the left of input field */
static const char *colors[SchemeLast][2] = { static const char *colors[SchemeLast][2] = {
/* fg bg */ /* fg bg */
[SchemeNorm] = { "#bbbbbb", "#222222" }, // [SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" }, // [SchemeSel] = { "#eeeeee", "#005577" },
// [SchemeOut] = { "#000000", "#00ffff" },
[SchemeNorm] = { "#222222", "#ffffff" },
[SchemeSel] = { "#ffffff", "#0b4c5f" },
[SchemeOut] = { "#000000", "#00ffff" }, [SchemeOut] = { "#000000", "#00ffff" },
// [SchemeNorm] = { "#bbbbbb", "#222222" },
// [SchemeSel] = { "#eeeeee", "#04B431" },
// [SchemeOut] = { "#000000", "#00ffff" },
}; };
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0; static unsigned int lines = 0;
@ -27,4 +36,4 @@ static unsigned int lines = 0;
static const char worddelimiters[] = " "; static const char worddelimiters[] = " ";
/* Size of the window border */ /* Size of the window border */
static const unsigned int border_width = 5; static const unsigned int border_width = 1;

11
config.h

@ -16,6 +16,15 @@ static const char *colors[SchemeLast][2] = {
[SchemeNorm] = { "#bbbbbb", "#222222" }, [SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" }, [SchemeSel] = { "#eeeeee", "#005577" },
[SchemeOut] = { "#000000", "#00ffff" }, [SchemeOut] = { "#000000", "#00ffff" },
// [SchemeNorm] = { "#222222", "#ffffff" },
// [SchemeSel] = { "#ffffff", "#0b4c5f" },
// [SchemeOut] = { "#000000", "#00ffff" },
// [SchemeNorm] = { "#bbbbbb", "#222222" },
// [SchemeSel] = { "#eeeeee", "#04B431" },
// [SchemeOut] = { "#000000", "#00ffff" },
}; };
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0; static unsigned int lines = 0;
@ -27,4 +36,4 @@ static unsigned int lines = 0;
static const char worddelimiters[] = " "; static const char worddelimiters[] = " ";
/* Size of the window border */ /* Size of the window border */
static const unsigned int border_width = 5; static const unsigned int border_width = 1;

BIN
dmenu

Binary file not shown.

25
dmenu.c

@ -25,6 +25,8 @@
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define LENGTH(X) (sizeof X / sizeof X[0]) #define LENGTH(X) (sizeof X / sizeof X[0])
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define NUMBERSMAXDIGITS 100
#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
/* enums */ /* enums */
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
@ -36,6 +38,7 @@ struct item {
double distance; double distance;
}; };
static char numbers[NUMBERSBUFSIZE] = "";
static char text[BUFSIZ] = ""; static char text[BUFSIZ] = "";
static char *embed; static char *embed;
static int bh, mw, mh; static int bh, mw, mh;
@ -138,6 +141,21 @@ drawitem(struct item *item, int x, int y, int w)
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
} }
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 static void
drawmenu(void) drawmenu(void)
{ {
@ -163,6 +181,7 @@ drawmenu(void)
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
} }
recalculatenumbers();
if (lines > 0) { if (lines > 0) {
/* draw vertical list */ /* draw vertical list */
for (item = curr; item != next; item = item->right) for (item = curr; item != next; item = item->right)
@ -177,13 +196,15 @@ drawmenu(void)
} }
x += w; x += w;
for (item = curr; item != next; item = item->right) 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) { if (next) {
w = TEXTW(">"); w = TEXTW(">");
drw_setscheme(drw, scheme[SchemeNorm]); 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); drw_map(drw, win, 0, 0, mw, mh);
} }

3
dmenu.c.orig

@ -770,9 +770,10 @@ setup(void)
swa.override_redirect = True; swa.override_redirect = True;
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0, win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width,
CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel);
XSetClassHint(dpy, win, &ch); XSetClassHint(dpy, win, &ch);

BIN
dmenu.o

Binary file not shown.

81
patches/dmenu-numbers-4.9.diff

@ -0,0 +1,81 @@
From 61abc60dbfaa8ec63fcd176307308aee88a19e32 Mon Sep 17 00:00:00 2001
From: Miles Alan <m@milesalan.com>
Date: Sat, 10 Aug 2019 17:20:08 -0500
Subject: [PATCH] Display number of matched and total items in top right corner
---
dmenu.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/dmenu.c b/dmenu.c
index 6b8f51b..98c5810 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -24,6 +24,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, 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;
@@ -126,6 +129,21 @@ drawitem(struct item *item, int x, int y, int w)
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
}
+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)
{
@@ -151,6 +169,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)
@@ -165,13 +184,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);
}
--
2.19.2
Loading…
Cancel
Save