summaryrefslogtreecommitdiff
path: root/dmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/dmenu.c b/dmenu.c
index 1153e6e..03327eb 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -26,7 +26,9 @@
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
+enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight,
+ SchemeOut, SchemeLast }; /* color schemes */
+
struct item {
char *text;
@@ -142,9 +144,47 @@ cistrstr(const char *h, const char *n)
return NULL;
}
+static void
+drawhighlights(struct item *item, int x, int y, int maxw)
+{
+ int i, indent;
+ char *highlight;
+ char c;
+
+ if (!(strlen(item->text) && strlen(text)))
+ return;
+
+ drw_setscheme(drw, scheme[item == sel
+ ? SchemeSelHighlight
+ : SchemeNormHighlight]);
+ for (i = 0, highlight = item->text; *highlight && text[i];) {
+ if (!fstrncmp(&text[i], highlight, 1)) {
+ c = highlight[1];
+ highlight[1] = '\0';
+
+ /* get indentation */
+ indent = TEXTW(item->text);
+
+ /* highlight character */
+ drw_text(
+ drw,
+ x + indent - lrpad,
+ y,
+ MIN(maxw - indent, TEXTW(highlight) - lrpad),
+ bh, 0, highlight, 0
+ );
+ highlight[1] = c;
+ i++;
+ }
+ highlight++;
+ }
+}
+
+
static int
drawitem(struct item *item, int x, int y, int w)
{
+ int r;
if (item == sel)
drw_setscheme(drw, scheme[SchemeSel]);
else if (item->out)
@@ -152,7 +192,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);
+ r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
+ drawhighlights(item, x, y, w);
+ return r;
}
static void
@@ -754,6 +796,7 @@ usage(void)
{
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n"
+ " [-nhb color] [-nhf color] [-shb color] [-shf color]\n"
" [-d separator] [-D separator]");
}
@@ -796,6 +839,14 @@ main(int argc, char *argv[])
colors[SchemeSel][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
colors[SchemeSel][ColFg] = argv[++i];
+ else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
+ colors[SchemeNormHighlight][ColBg] = argv[++i];
+ else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
+ colors[SchemeNormHighlight][ColFg] = argv[++i];
+ else if (!strcmp(argv[i], "-shb")) /* selected hi background color */
+ colors[SchemeSelHighlight][ColBg] = argv[++i];
+ else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
+ colors[SchemeSelHighlight][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
else if (!strcmp(argv[i], "-bw"))