Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c2064551d | |||
| 663223e5cb | |||
| d6f94be232 | |||
| 216cc2d1e9 | |||
| 63578c2de6 | |||
| 0c6183b640 | |||
| 6d926e2f98 | |||
| 89e74aaee0 | |||
| 4dbee5bdb9 | |||
| 46283b1fdd | |||
| eeb709e3dd | |||
| 6f3a6f1b3b | |||
| 7b85e7deee | |||
| d8b3151387 | |||
| 402cc706fb | |||
| 8e73a358d9 | |||
| 39042c71d7 |
2
Makefile
2
Makefile
@ -23,7 +23,7 @@ stest: stest.o
|
|||||||
$(CC) -o $@ stest.o $(LDFLAGS)
|
$(CC) -o $@ stest.o $(LDFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f dmenu stest $(OBJ) dmenu-$(VERSION).tar.gz
|
rm -f dmenu stest $(OBJ) dmenu-$(VERSION).tar.gz config.h
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
mkdir -p dmenu-$(VERSION)
|
mkdir -p dmenu-$(VERSION)
|
||||||
|
|||||||
23
config.def.h
23
config.def.h
@ -2,20 +2,31 @@
|
|||||||
/* Default settings; can be overriden by command line. */
|
/* Default settings; can be overriden by command line. */
|
||||||
|
|
||||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||||
|
|
||||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||||
static const char *fonts[] = {
|
static const char *fonts[] = {
|
||||||
"monospace:size=10"
|
"xft:FiraCode Nerd Font:size=10:antialias=true:hinting=true"};
|
||||||
};
|
|
||||||
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] = {"#D5C4A1", "#262626"},
|
||||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
[SchemeSel] = {"#262626", "#FE8019"},
|
||||||
[SchemeOut] = { "#000000", "#00ffff" },
|
[SchemeSelHighlight] = {"#665c54", "#fbf1c7"},
|
||||||
|
[SchemeNormHighlight] = {"#D5C4A1", "#262626"},
|
||||||
|
[SchemeOut] = {"#000000", "#00ffff"},
|
||||||
|
[SchemeOutHighlight] = {"#ffc978", "#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;
|
||||||
|
|
||||||
|
/* -h option; minimum height of a menu line */
|
||||||
|
static unsigned int lineheight = 20;
|
||||||
|
static unsigned int min_lineheight = 8;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Characters not considered part of a word while deleting words
|
* Characters not considered part of a word while deleting words
|
||||||
* for example: " /?\"&[]"
|
* for example: " /?\"&[]"
|
||||||
|
|||||||
97
dmenu-highlight-20201211-fcdc159.diff
Normal file
97
dmenu-highlight-20201211-fcdc159.diff
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
From fcdc1593ed418166f20b7e691a49b1e6eefc116e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Nathaniel Evan <nathanielevan@zohomail.com>
|
||||||
|
Date: Fri, 11 Dec 2020 11:08:12 +0700
|
||||||
|
Subject: [PATCH] Highlight matched text in a different color scheme
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 3 +++
|
||||||
|
dmenu.c | 44 +++++++++++++++++++++++++++++++++++++++++---
|
||||||
|
2 files changed, 44 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1edb647..79be73a 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -11,7 +11,10 @@ static const char *colors[SchemeLast][2] = {
|
||||||
|
/* fg bg */
|
||||||
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
|
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||||
|
+ [SchemeSelHighlight] = { "#ffc978", "#005577" },
|
||||||
|
+ [SchemeNormHighlight] = { "#ffc978", "#222222" },
|
||||||
|
[SchemeOut] = { "#000000", "#00ffff" },
|
||||||
|
+ [SchemeOutHighlight] = { "#ffc978", "#00ffff" },
|
||||||
|
};
|
||||||
|
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
|
static unsigned int lines = 0;
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index 65f25ce..cce1ad1 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -26,8 +26,7 @@
|
||||||
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||||
|
|
||||||
|
/* enums */
|
||||||
|
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
|
||||||
|
-
|
||||||
|
+enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */
|
||||||
|
struct item {
|
||||||
|
char *text;
|
||||||
|
struct item *left, *right;
|
||||||
|
@@ -113,6 +112,43 @@ cistrstr(const char *s, const char *sub)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
+static void
|
||||||
|
+drawhighlights(struct item *item, int x, int y, int maxw)
|
||||||
|
+{
|
||||||
|
+ char restorechar, tokens[sizeof text], *highlight, *token;
|
||||||
|
+ int indentx, highlightlen;
|
||||||
|
+
|
||||||
|
+ drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : item->out ? SchemeOutHighlight : SchemeNormHighlight]);
|
||||||
|
+ strcpy(tokens, text);
|
||||||
|
+ for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
|
||||||
|
+ highlight = fstrstr(item->text, token);
|
||||||
|
+ while (highlight) {
|
||||||
|
+ // Move item str end, calc width for highlight indent, & restore
|
||||||
|
+ highlightlen = highlight - item->text;
|
||||||
|
+ restorechar = *highlight;
|
||||||
|
+ item->text[highlightlen] = '\0';
|
||||||
|
+ indentx = TEXTW(item->text);
|
||||||
|
+ item->text[highlightlen] = restorechar;
|
||||||
|
+
|
||||||
|
+ // Move highlight str end, draw highlight, & restore
|
||||||
|
+ restorechar = highlight[strlen(token)];
|
||||||
|
+ highlight[strlen(token)] = '\0';
|
||||||
|
+ if (indentx - (lrpad / 2) - 1 < maxw)
|
||||||
|
+ drw_text(
|
||||||
|
+ drw,
|
||||||
|
+ x + indentx - (lrpad / 2) - 1,
|
||||||
|
+ y,
|
||||||
|
+ MIN(maxw - indentx, TEXTW(highlight) - lrpad),
|
||||||
|
+ bh, 0, highlight, 0
|
||||||
|
+ );
|
||||||
|
+ highlight[strlen(token)] = restorechar;
|
||||||
|
+
|
||||||
|
+ if (strlen(highlight) - strlen(token) < strlen(token)) break;
|
||||||
|
+ highlight = fstrstr(highlight + strlen(token), token);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
static int
|
||||||
|
drawitem(struct item *item, int x, int y, int w)
|
||||||
|
{
|
||||||
|
@@ -123,7 +159,9 @@ drawitem(struct item *item, int x, int y, int w)
|
||||||
|
else
|
||||||
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
|
||||||
|
- return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||||
|
+ int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||||
|
+ drawhighlights(item, x, y, w);
|
||||||
|
+ return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
--
|
||||||
|
2.29.2
|
||||||
|
|
||||||
106
dmenu-lineheight-5.2.diff
Normal file
106
dmenu-lineheight-5.2.diff
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
From ba103e38ea4ab07f9a3ee90627714b9bea17c329 Mon Sep 17 00:00:00 2001
|
||||||
|
From: pskry <peter@skrypalle.dk>
|
||||||
|
Date: Sun, 8 Nov 2020 22:04:22 +0100
|
||||||
|
Subject: [PATCH] Add an option which defines the lineheight
|
||||||
|
|
||||||
|
Despite both the panel and dmenu using the same font (a Terminus 12),
|
||||||
|
dmenu is shorter and the panel is visible from under the dmenu bar.
|
||||||
|
The appearance can be even more distracting when using similar colors
|
||||||
|
for background and selections. With the option added by this patch,
|
||||||
|
dmenu can be launched with a '-h 24', thus completely covering the panel.
|
||||||
|
---
|
||||||
|
config.def.h | 3 +++
|
||||||
|
dmenu.1 | 5 +++++
|
||||||
|
dmenu.c | 11 ++++++++---
|
||||||
|
3 files changed, 16 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 1edb647..4394dec 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -15,6 +15,9 @@ static const char *colors[SchemeLast][2] = {
|
||||||
|
};
|
||||||
|
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
|
static unsigned int lines = 0;
|
||||||
|
+/* -h option; minimum height of a menu line */
|
||||||
|
+static unsigned int lineheight = 0;
|
||||||
|
+static unsigned int min_lineheight = 8;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters not considered part of a word while deleting words
|
||||||
|
diff --git a/dmenu.1 b/dmenu.1
|
||||||
|
index 323f93c..f2a82b4 100644
|
||||||
|
--- a/dmenu.1
|
||||||
|
+++ b/dmenu.1
|
||||||
|
@@ -6,6 +6,8 @@ dmenu \- dynamic menu
|
||||||
|
.RB [ \-bfiv ]
|
||||||
|
.RB [ \-l
|
||||||
|
.IR lines ]
|
||||||
|
+.RB [ \-h
|
||||||
|
+.IR height ]
|
||||||
|
.RB [ \-m
|
||||||
|
.IR monitor ]
|
||||||
|
.RB [ \-p
|
||||||
|
@@ -50,6 +52,9 @@ dmenu matches menu items case insensitively.
|
||||||
|
.BI \-l " lines"
|
||||||
|
dmenu lists items vertically, with the given number of lines.
|
||||||
|
.TP
|
||||||
|
+.BI \-h " height"
|
||||||
|
+dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
|
||||||
|
+.TP
|
||||||
|
.BI \-m " monitor"
|
||||||
|
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
||||||
|
from 0.
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index e7be8af..82b204b 100644
|
||||||
|
--- a/dmenu.c
|
||||||
|
+++ b/dmenu.c
|
||||||
|
@@ -148,7 +148,7 @@ drawmenu(void)
|
||||||
|
{
|
||||||
|
unsigned int curpos;
|
||||||
|
struct item *item;
|
||||||
|
- int x = 0, y = 0, w;
|
||||||
|
+ int x = 0, y = 0, fh = drw->fonts->h, w;
|
||||||
|
|
||||||
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||||
|
@@ -165,7 +165,7 @@ drawmenu(void)
|
||||||
|
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||||
|
if ((curpos += lrpad / 2 - 1) < w) {
|
||||||
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
||||||
|
+ drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines > 0) {
|
||||||
|
@@ -630,6 +630,7 @@ setup(void)
|
||||||
|
|
||||||
|
/* calculate menu geometry */
|
||||||
|
bh = drw->fonts->h + 2;
|
||||||
|
+ bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
|
||||||
|
lines = MAX(lines, 0);
|
||||||
|
mh = (lines + 1) * bh;
|
||||||
|
#ifdef XINERAMA
|
||||||
|
@@ -710,7 +711,7 @@ setup(void)
|
||||||
|
static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
- die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||||
|
+ die("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
|
||||||
|
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -737,6 +738,10 @@ main(int argc, char *argv[])
|
||||||
|
/* these options take one argument */
|
||||||
|
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
||||||
|
lines = atoi(argv[++i]);
|
||||||
|
+ else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
|
||||||
|
+ lineheight = atoi(argv[++i]);
|
||||||
|
+ lineheight = MAX(lineheight, min_lineheight);
|
||||||
|
+ }
|
||||||
|
else if (!strcmp(argv[i], "-m"))
|
||||||
|
mon = atoi(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
|
||||||
|
--
|
||||||
|
2.38.1
|
||||||
|
|
||||||
89
dmenu-numbers-20220512-28fb3e2.diff
Normal file
89
dmenu-numbers-20220512-28fb3e2.diff
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
From c4cd209c2e322563750d09a3b64194d11cc12a10 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Ehsan Ghorbannezhad <ehsan@disroot.org>
|
||||||
|
Date: Thu, 12 May 2022 22:32:47 +0430
|
||||||
|
Subject: [PATCH] the numbers patch, updated to fix segfault in some conditions
|
||||||
|
|
||||||
|
---
|
||||||
|
dmenu.c | 27 ++++++++++++++++++++++++---
|
||||||
|
1 file changed, 24 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/dmenu.c b/dmenu.c
|
||||||
|
index 571bc35..70004e7 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;
|
||||||
|
@@ -86,7 +89,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)
|
||||||
|
@@ -143,6 +146,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)
|
||||||
|
{
|
||||||
|
@@ -168,6 +186,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)
|
||||||
|
@@ -182,13 +201,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);
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.36.1
|
||||||
5
dmenu.1
5
dmenu.1
@ -6,6 +6,8 @@ dmenu \- dynamic menu
|
|||||||
.RB [ \-bfiv ]
|
.RB [ \-bfiv ]
|
||||||
.RB [ \-l
|
.RB [ \-l
|
||||||
.IR lines ]
|
.IR lines ]
|
||||||
|
.RB [ \-h
|
||||||
|
.IR height ]
|
||||||
.RB [ \-m
|
.RB [ \-m
|
||||||
.IR monitor ]
|
.IR monitor ]
|
||||||
.RB [ \-p
|
.RB [ \-p
|
||||||
@ -50,6 +52,9 @@ dmenu matches menu items case insensitively.
|
|||||||
.BI \-l " lines"
|
.BI \-l " lines"
|
||||||
dmenu lists items vertically, with the given number of lines.
|
dmenu lists items vertically, with the given number of lines.
|
||||||
.TP
|
.TP
|
||||||
|
.BI \-h " height"
|
||||||
|
dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
|
||||||
|
.TP
|
||||||
.BI \-m " monitor"
|
.BI \-m " monitor"
|
||||||
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
|
||||||
from 0.
|
from 0.
|
||||||
|
|||||||
82
dmenu.c
82
dmenu.c
@ -23,16 +23,18 @@
|
|||||||
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
|
#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)))
|
* 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 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, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
char *text;
|
char *text;
|
||||||
struct item *left, *right;
|
struct item *left, *right;
|
||||||
int out;
|
int out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
@ -85,7 +87,7 @@ calcoffsets(void)
|
|||||||
if (lines > 0)
|
if (lines > 0)
|
||||||
n = lines * bh;
|
n = lines * bh;
|
||||||
else
|
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 */
|
/* calculate which items will begin the next page and previous page */
|
||||||
for (i = 0, next = curr; next; next = next->right)
|
for (i = 0, next = curr; next; next = next->right)
|
||||||
if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)) > n)
|
if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)) > n)
|
||||||
@ -129,6 +131,43 @@ cistrstr(const char *h, const char *n)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawhighlights(struct item *item, int x, int y, int maxw)
|
||||||
|
{
|
||||||
|
char restorechar, tokens[sizeof text], *highlight, *token;
|
||||||
|
int indentx, highlightlen;
|
||||||
|
|
||||||
|
drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : item->out ? SchemeOutHighlight : SchemeNormHighlight]);
|
||||||
|
strcpy(tokens, text);
|
||||||
|
for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
|
||||||
|
highlight = fstrstr(item->text, token);
|
||||||
|
while (highlight) {
|
||||||
|
// Move item str end, calc width for highlight indent, & restore
|
||||||
|
highlightlen = highlight - item->text;
|
||||||
|
restorechar = *highlight;
|
||||||
|
item->text[highlightlen] = '\0';
|
||||||
|
indentx = TEXTW(item->text);
|
||||||
|
item->text[highlightlen] = restorechar;
|
||||||
|
|
||||||
|
// Move highlight str end, draw highlight, & restore
|
||||||
|
restorechar = highlight[strlen(token)];
|
||||||
|
highlight[strlen(token)] = '\0';
|
||||||
|
if (indentx - (lrpad / 2) - 1 < maxw)
|
||||||
|
drw_text(
|
||||||
|
drw,
|
||||||
|
x + indentx - (lrpad / 2) - 1,
|
||||||
|
y,
|
||||||
|
MIN(maxw - indentx, TEXTW(highlight) - lrpad),
|
||||||
|
bh, 0, highlight, 0
|
||||||
|
);
|
||||||
|
highlight[strlen(token)] = restorechar;
|
||||||
|
|
||||||
|
if (strlen(highlight) - strlen(token) < strlen(token)) break;
|
||||||
|
highlight = fstrstr(highlight + strlen(token), token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
drawitem(struct item *item, int x, int y, int w)
|
drawitem(struct item *item, int x, int y, int w)
|
||||||
{
|
{
|
||||||
@ -139,7 +178,24 @@ drawitem(struct item *item, int x, int y, int w)
|
|||||||
else
|
else
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
|
||||||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||||
|
drawhighlights(item, x, y, w);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@ -147,7 +203,7 @@ drawmenu(void)
|
|||||||
{
|
{
|
||||||
unsigned int curpos;
|
unsigned int curpos;
|
||||||
struct item *item;
|
struct item *item;
|
||||||
int x = 0, y = 0, w;
|
int x = 0, y = 0, fh = drw->fonts->h, w;
|
||||||
|
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||||
@ -164,9 +220,10 @@ drawmenu(void)
|
|||||||
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
||||||
if ((curpos += lrpad / 2 - 1) < w) {
|
if ((curpos += lrpad / 2 - 1) < w) {
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
|
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 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)
|
||||||
@ -181,13 +238,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, textw_clamp(item->text, mw - x - TEXTW(">")));
|
x = drawitem(item, x, 0, textw_clamp(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,6 +693,7 @@ setup(void)
|
|||||||
|
|
||||||
/* calculate menu geometry */
|
/* calculate menu geometry */
|
||||||
bh = drw->fonts->h + 2;
|
bh = drw->fonts->h + 2;
|
||||||
|
bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
|
||||||
lines = MAX(lines, 0);
|
lines = MAX(lines, 0);
|
||||||
mh = (lines + 1) * bh;
|
mh = (lines + 1) * bh;
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
@ -714,7 +774,7 @@ setup(void)
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
die("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
|
||||||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
|
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,6 +801,10 @@ main(int argc, char *argv[])
|
|||||||
/* these options take one argument */
|
/* these options take one argument */
|
||||||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
||||||
lines = atoi(argv[++i]);
|
lines = atoi(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
|
||||||
|
lineheight = atoi(argv[++i]);
|
||||||
|
lineheight = MAX(lineheight, min_lineheight);
|
||||||
|
}
|
||||||
else if (!strcmp(argv[i], "-m"))
|
else if (!strcmp(argv[i], "-m"))
|
||||||
mon = atoi(argv[++i]);
|
mon = atoi(argv[++i]);
|
||||||
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
|
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user