dmenu

[fork] X11 menuing
Log | Files | Refs | README | LICENSE

commit 279c3b1a06667072c5dd68056f5479ffd4b19e70
parent 70a09caa86fd51b941f9252927378c0ae2df9a5b
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 13 Jun 2021 15:48:54 +0100

config.h dmenu.c dmenu.1: import fuzzyhilight patch

Diffstat:
Mconfig.h | 5+++--
Mdmenu.1 | 20++++++++++++++++++++
Mdmenu.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 81 insertions(+), 6 deletions(-)

diff --git a/config.h b/config.h @@ -14,12 +14,13 @@ static const char *fonts[] = { }; static const char *prompt = NULL; /* -p option; prompt to the left of input field */ static const char *colors[SchemeLast][2] = { - /* fg bg */ [SchemeNorm] = { "#ffffff", "#050a10" }, [SchemeSel] = { "#ffffff", "#0a2126" }, [SchemeOut] = { "#000000", "#00ffff" }, - [SchemeMid] = { "#ffffff", "#050a10" }, [SchemeBorder] = { "#ffffff", "#892b2b" }, + + [SchemeNormHighlight] = { "#aafff0", "#050a10" }, + [SchemeSelHighlight] = { "#aafff0", "#0a2126" }, }; /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ static unsigned int lines=20; diff --git a/dmenu.1 b/dmenu.1 @@ -20,6 +20,14 @@ dmenu \- dynamic menu .IR color ] .RB [ \-sf .IR color ] +.RB [ \-nhb +.IR color ] +.RB [ \-nhf +.IR color ] +.RB [ \-shb +.IR color ] +.RB [ \-shf +.IR color ] .RB [ \-w .IR windowid ] .P @@ -105,6 +113,18 @@ defines the selected background color. .BI \-sf " color" defines the selected foreground color. .TP +.BI \-nhb " color" +defines the normal highlight background color. +.TP +.BI \-nhf " color" +defines the normal highlight foreground color. +.TP +.BI \-shb " color" +defines the selected highlight background color. +.TP +.BI \-shf " color" +defines the selected highlight foreground color. +.TP .B \-v prints version information to stdout, then exits. .TP diff --git a/dmenu.c b/dmenu.c @@ -29,7 +29,11 @@ #define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 /* enums */ -enum { SchemeBorder, SchemeNorm, SchemeSel, SchemeOut, SchemeMid, SchemeLast }; /* color schemes */ +enum { + SchemeBorder, SchemeNorm, SchemeSel, SchemeOut, + SchemeSelHighlight, SchemeNormHighlight, + SchemeLast +}; struct item { char *text; @@ -127,14 +131,52 @@ cistrstr(const char *s, const char *sub) return NULL; } +static void +drw_highlights(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 (*highlight == text[i]) { + /* get indentation */ + c = *highlight; + *highlight = '\0'; + indent = TEXTW(item->text); + *highlight = c; + + /* highlight character */ + c = highlight[1]; + highlight[1] = '\0'; + drw_text( + drw, + x + indent - (lrpad / 2), + 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) { char *censort; + int ret; + if (item == sel) drw_setscheme(drw, scheme[SchemeSel]); - else if (item->left == sel || item->right == sel) - drw_setscheme(drw, scheme[SchemeMid]); else if (item->out) drw_setscheme(drw, scheme[SchemeOut]); else @@ -146,7 +188,11 @@ drawitem(struct item *item, int x, int y, int w) memset(censort, '|', (r % 50)+25); drw_text(drw, x, y, w, bh, lrpad / 2, censort, 0); free(censort); - } else return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); + } else { + ret = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); + drw_highlights(item, x, y, w); + return ret; + } } static void @@ -914,6 +960,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"))