diff options
author | Sam Chudnick <sam@chudnick.com> | 2023-02-25 22:08:18 -0500 |
---|---|---|
committer | Sam Chudnick <sam@chudnick.com> | 2023-02-25 22:08:18 -0500 |
commit | 494b7fe74a8dc334a5b0345c84814ec3d8316999 (patch) | |
tree | 5d89190d9f317fcd4764fd1b3322ff74bad81671 | |
parent | 66d02ca70f0d58bce2f7f4da72e3fc090d4cba6d (diff) |
Apply highlight patch
-rw-r--r-- | config.h | 3 | ||||
-rwxr-xr-x | dmenu | bin | 44432 -> 0 bytes | |||
-rw-r--r-- | dmenu.c | 44 | ||||
-rwxr-xr-x | stest | bin | 17680 -> 0 bytes |
4 files changed, 44 insertions, 3 deletions
@@ -13,7 +13,10 @@ 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" }, | ||
16 | [SchemeOut] = { "#000000", "#00ffff" }, | 18 | [SchemeOut] = { "#000000", "#00ffff" }, |
19 | [SchemeOutHighlight] = { "#ffc978", "#00ffff" }, | ||
17 | }; | 20 | }; |
18 | 21 | ||
19 | static const unsigned int alphas[SchemeLast][2] = { | 22 | static const unsigned int alphas[SchemeLast][2] = { |
Binary files differ | |||
@@ -30,8 +30,7 @@ | |||
30 | #define OPAQUE 0xffU | 30 | #define OPAQUE 0xffU |
31 | 31 | ||
32 | /* enums */ | 32 | /* enums */ |
33 | enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ | 33 | enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */ |
34 | |||
35 | struct item { | 34 | struct item { |
36 | char *text; | 35 | char *text; |
37 | struct item *left, *right; | 36 | struct item *left, *right; |
@@ -141,6 +140,43 @@ cistrstr(const char *h, const char *n) | |||
141 | return NULL; | 140 | return NULL; |
142 | } | 141 | } |
143 | 142 | ||
143 | static void | ||
144 | drawhighlights(struct item *item, int x, int y, int maxw) | ||
145 | { | ||
146 | char restorechar, tokens[sizeof text], *highlight, *token; | ||
147 | int indentx, highlightlen; | ||
148 | |||
149 | drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : item->out ? SchemeOutHighlight : SchemeNormHighlight]); | ||
150 | strcpy(tokens, text); | ||
151 | for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) { | ||
152 | highlight = fstrstr(item->text, token); | ||
153 | while (highlight) { | ||
154 | // Move item str end, calc width for highlight indent, & restore | ||
155 | highlightlen = highlight - item->text; | ||
156 | restorechar = *highlight; | ||
157 | item->text[highlightlen] = '\0'; | ||
158 | indentx = TEXTW(item->text); | ||
159 | item->text[highlightlen] = restorechar; | ||
160 | |||
161 | // Move highlight str end, draw highlight, & restore | ||
162 | restorechar = highlight[strlen(token)]; | ||
163 | highlight[strlen(token)] = '\0'; | ||
164 | if (indentx - (lrpad / 2) - 1 < maxw) | ||
165 | drw_text( | ||
166 | drw, | ||
167 | x + indentx - (lrpad / 2) - 1, | ||
168 | y, | ||
169 | MIN(maxw - indentx, TEXTW(highlight) - lrpad), | ||
170 | bh, 0, highlight, 0 | ||
171 | ); | ||
172 | highlight[strlen(token)] = restorechar; | ||
173 | |||
174 | if (strlen(highlight) - strlen(token) < strlen(token)) break; | ||
175 | highlight = fstrstr(highlight + strlen(token), token); | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
144 | static int | 180 | static int |
145 | drawitem(struct item *item, int x, int y, int w) | 181 | drawitem(struct item *item, int x, int y, int w) |
146 | { | 182 | { |
@@ -151,7 +187,9 @@ drawitem(struct item *item, int x, int y, int w) | |||
151 | else | 187 | else |
152 | drw_setscheme(drw, scheme[SchemeNorm]); | 188 | drw_setscheme(drw, scheme[SchemeNorm]); |
153 | 189 | ||
154 | return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); | 190 | int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); |
191 | drawhighlights(item, x, y, w); | ||
192 | return r; | ||
155 | } | 193 | } |
156 | 194 | ||
157 | static void | 195 | static void |
Binary files differ | |||