aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2023-02-25 22:08:18 -0500
committerSam Chudnick <sam@chudnick.com>2023-02-25 22:08:18 -0500
commit494b7fe74a8dc334a5b0345c84814ec3d8316999 (patch)
tree5d89190d9f317fcd4764fd1b3322ff74bad81671
parent66d02ca70f0d58bce2f7f4da72e3fc090d4cba6d (diff)
Apply highlight patch
-rw-r--r--config.h3
-rwxr-xr-xdmenubin44432 -> 0 bytes
-rw-r--r--dmenu.c44
-rwxr-xr-xstestbin17680 -> 0 bytes
4 files changed, 44 insertions, 3 deletions
diff --git a/config.h b/config.h
index 5893d0b..bf22598 100644
--- a/config.h
+++ b/config.h
@@ -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
19static const unsigned int alphas[SchemeLast][2] = { 22static const unsigned int alphas[SchemeLast][2] = {
diff --git a/dmenu b/dmenu
deleted file mode 100755
index 63f1aea..0000000
--- a/dmenu
+++ /dev/null
Binary files differ
diff --git a/dmenu.c b/dmenu.c
index 9cfb1c4..635f204 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -30,8 +30,7 @@
30#define OPAQUE 0xffU 30#define OPAQUE 0xffU
31 31
32/* enums */ 32/* enums */
33enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ 33enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeOutHighlight, SchemeLast }; /* color schemes */
34
35struct item { 34struct 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
143static void
144drawhighlights(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
144static int 180static int
145drawitem(struct item *item, int x, int y, int w) 181drawitem(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
157static void 195static void
diff --git a/stest b/stest
deleted file mode 100755
index d2d6ca3..0000000
--- a/stest
+++ /dev/null
Binary files differ