aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h3
-rw-r--r--dmenu.c44
2 files changed, 3 insertions, 44 deletions
diff --git a/config.h b/config.h
index bf22598..5893d0b 100644
--- a/config.h
+++ b/config.h
@@ -13,10 +13,7 @@ static const char *colors[SchemeLast][2] = {
13 /* fg bg */ 13 /* fg bg */
14 [SchemeNorm] = { "#bbbbbb", "#222222" }, 14 [SchemeNorm] = { "#bbbbbb", "#222222" },
15 [SchemeSel] = { "#eeeeee", "#005577" }, 15 [SchemeSel] = { "#eeeeee", "#005577" },
16 [SchemeSelHighlight] = { "#ffc978", "#005577" },
17 [SchemeNormHighlight] = { "#ffc978", "#222222" },
18 [SchemeOut] = { "#000000", "#00ffff" }, 16 [SchemeOut] = { "#000000", "#00ffff" },
19 [SchemeOutHighlight] = { "#ffc978", "#00ffff" },
20}; 17};
21 18
22static const unsigned int alphas[SchemeLast][2] = { 19static const unsigned int alphas[SchemeLast][2] = {
diff --git a/dmenu.c b/dmenu.c
index 431e84f..0dc940b 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -31,7 +31,8 @@
31#define OPAQUE 0xffU 31#define OPAQUE 0xffU
32 32
33/* enums */ 33/* enums */
34enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */ 34enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
35
35struct item { 36struct item {
36 char *text; 37 char *text;
37 struct item *left, *right; 38 struct item *left, *right;
@@ -145,43 +146,6 @@ cistrstr(const char *h, const char *n)
145 return NULL; 146 return NULL;
146} 147}
147 148
148static void
149drawhighlights(struct item *item, int x, int y, int maxw)
150{
151 char restorechar, tokens[sizeof text], *highlight, *token;
152 int indentx, highlightlen;
153
154 drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : item->out ? SchemeOutHighlight : SchemeNormHighlight]);
155 strcpy(tokens, text);
156 for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
157 highlight = fstrstr(item->text, token);
158 while (highlight) {
159 // Move item str end, calc width for highlight indent, & restore
160 highlightlen = highlight - item->text;
161 restorechar = *highlight;
162 item->text[highlightlen] = '\0';
163 indentx = TEXTW(item->text);
164 item->text[highlightlen] = restorechar;
165
166 // Move highlight str end, draw highlight, & restore
167 restorechar = highlight[strlen(token)];
168 highlight[strlen(token)] = '\0';
169 if (indentx - (lrpad / 2) - 1 < maxw)
170 drw_text(
171 drw,
172 x + indentx - (lrpad / 2) - 1,
173 y,
174 MIN(maxw - indentx, TEXTW(highlight) - lrpad),
175 bh, 0, highlight, 0
176 );
177 highlight[strlen(token)] = restorechar;
178
179 if (strlen(highlight) - strlen(token) < strlen(token)) break;
180 highlight = fstrstr(highlight + strlen(token), token);
181 }
182 }
183}
184
185static int 149static int
186drawitem(struct item *item, int x, int y, int w) 150drawitem(struct item *item, int x, int y, int w)
187{ 151{
@@ -192,9 +156,7 @@ drawitem(struct item *item, int x, int y, int w)
192 else 156 else
193 drw_setscheme(drw, scheme[SchemeNorm]); 157 drw_setscheme(drw, scheme[SchemeNorm]);
194 158
195 int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); 159 return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
196 drawhighlights(item, x, y, w);
197 return r;
198} 160}
199 161
200static void 162static void