From aa74459a4eb561022f57db3408ce8ce77944a9fb Mon Sep 17 00:00:00 2001 From: Deven Blake Date: Sat, 15 May 2021 23:45:35 -0400 Subject: [PATCH] back at it --- dmenubar/dmenu.c | 62 ++---------------------------------------------- 1 file changed, 2 insertions(+), 60 deletions(-) diff --git a/dmenubar/dmenu.c b/dmenubar/dmenu.c index 3f6111d..bf5a9e0 100644 --- a/dmenubar/dmenu.c +++ b/dmenubar/dmenu.c @@ -114,74 +114,17 @@ drawitem(struct item *item, int x, int y, int w) static void drawmenu(void) { - struct item *item; int x = 0, y = 0, w; - drw_setscheme(drw, scheme[SchemeNorm]); + drw_setscheme(drw, scheme[SchemeSel]); drw_rect(drw, 0, 0, mw, mh, 1, 1); - if (prompt && *prompt) { - drw_setscheme(drw, scheme[SchemeSel]); + if (prompt && *prompt) x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); - } drw_map(drw, win, 0, 0, mw, mh); } -static void -match(void) -{ - static char **tokv = NULL; - static int tokn = 0; - - char buf[sizeof text], *s; - int i, tokc = 0; - size_t len, textsize; - struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; - - strcpy(buf, text); - /* separate input text into tokens to be matched individually */ - for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) - if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) - die("cannot realloc %u bytes:", tokn * sizeof *tokv); - len = tokc ? strlen(tokv[0]) : 0; - - matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; - textsize = strlen(text) + 1; - for (item = items; item && item->text; item++) { - for (i = 0; i < tokc; i++) - if (!fstrstr(item->text, tokv[i])) - break; - if (i != tokc) /* not all tokens match */ - continue; - /* exact matches go first, then prefixes, then substrings */ - if (!tokc || !fstrncmp(text, item->text, textsize)) - appenditem(item, &matches, &matchend); - else if (!fstrncmp(tokv[0], item->text, len)) - appenditem(item, &lprefix, &prefixend); - else - appenditem(item, &lsubstr, &substrend); - } - if (lprefix) { - if (matches) { - matchend->right = lprefix; - lprefix->left = matchend; - } else - matches = lprefix; - matchend = prefixend; - } - if (lsubstr) { - if (matches) { - matchend->right = lsubstr; - lsubstr->left = matchend; - } else - matches = lsubstr; - matchend = substrend; - } - curr = sel = matches; - calcoffsets(); -} - static void readstdin(void) { @@ -277,7 +220,6 @@ setup(void) } promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; inputw = MIN(inputw, mw/3); - match(); /* create menu window */ swa.override_redirect = True;