mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 14:05:48 +02:00
Adding highlight patch
This commit is contained in:
parent
768b5527ab
commit
aa50b3f2c5
@ -15,7 +15,7 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
|
||||
|
||||
### Changelog:
|
||||
|
||||
2020-08-05 - Added the grid, dynamic options and numbers patches
|
||||
2020-08-05 - Added the grid, highlight, dynamic options and numbers patches
|
||||
|
||||
2020-06-13 - Added the pango patch
|
||||
|
||||
@ -64,6 +64,9 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
|
||||
- allows dmenu's entries to be rendered in a grid by adding a new `-g` flag to specify the number of grid columns
|
||||
- the `-g` and `-l` options can be used together to create a G columns * L lines grid
|
||||
|
||||
- [highlight](https://tools.suckless.org/dmenu/patches/highlight/)
|
||||
- this patch highlights the individual characters of matched text for each dmenu list entry
|
||||
|
||||
- [incremental](https://tools.suckless.org/dmenu/patches/incremental/)
|
||||
- this patch causes dmenu to print out the current text each time a key is pressed
|
||||
|
||||
|
@ -56,10 +56,10 @@ static const char *colors[][2] =
|
||||
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||
[SchemeOut] = { "#000000", "#00ffff" },
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||
[SchemeSelHighlight] = { "#ffc978", "#005577" },
|
||||
[SchemeNormHighlight] = { "#ffc978", "#222222" },
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||
};
|
||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||
static unsigned int lines = 0;
|
||||
|
22
dmenu.c
22
dmenu.c
@ -40,10 +40,10 @@ enum {
|
||||
SchemeNorm,
|
||||
SchemeSel,
|
||||
SchemeOut,
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||
SchemeNormHighlight,
|
||||
SchemeSelHighlight,
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
#endif // HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||
SchemeLast,
|
||||
}; /* color schemes */
|
||||
|
||||
@ -214,9 +214,7 @@ cistrstr(const char *s, const char *sub)
|
||||
static int
|
||||
drawitem(struct item *item, int x, int y, int w)
|
||||
{
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
int r;
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
if (item == sel)
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
else if (item->out)
|
||||
@ -224,19 +222,15 @@ drawitem(struct item *item, int x, int y, int w)
|
||||
else
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#if PANGO_PATCH
|
||||
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0, True);
|
||||
#else
|
||||
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
#endif // PANGO_PATCH
|
||||
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||
drawhighlights(item, x, y, w);
|
||||
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||
return r;
|
||||
#elif PANGO_PATCH
|
||||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0, True);
|
||||
#else
|
||||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1308,9 +1302,9 @@ usage(void)
|
||||
#if XYW_PATCH
|
||||
" [-X xoffset] [-Y yoffset] [-W width]" // (arguments made upper case due to conflicts)
|
||||
#endif // XYW_PATCH
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||
"\n [-nhb color] [-nhf color] [-shb color] [-shf color]" // highlight colors
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||
"\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
@ -1428,7 +1422,7 @@ main(int argc, char *argv[])
|
||||
colors[SchemeSel][ColBg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
|
||||
colors[SchemeSel][ColFg] = argv[++i];
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||
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 */
|
||||
@ -1437,7 +1431,7 @@ main(int argc, char *argv[])
|
||||
colors[SchemeSelHighlight][ColBg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
|
||||
colors[SchemeSelHighlight][ColFg] = argv[++i];
|
||||
#endif // FUZZYHIGHLIGHT_PATCH
|
||||
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
#if DYNAMIC_OPTIONS_PATCH
|
||||
|
37
patch/highlight.c
Normal file
37
patch/highlight.c
Normal file
@ -0,0 +1,37 @@
|
||||
static void
|
||||
drawhighlights(struct item *item, int x, int y, int maxw)
|
||||
{
|
||||
char restorechar, tokens[sizeof text], *highlight, *token;
|
||||
int indentx, highlightlen;
|
||||
|
||||
drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]);
|
||||
strcpy(tokens, text);
|
||||
for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
|
||||
highlight = fstrstr(item->text, token);
|
||||
while (highlight) {
|
||||
// Move item str end, calc width for highlight indent, & restore
|
||||
highlightlen = highlight - item->text;
|
||||
restorechar = *highlight;
|
||||
item->text[highlightlen] = '\0';
|
||||
indentx = TEXTW(item->text);
|
||||
item->text[highlightlen] = restorechar;
|
||||
|
||||
// Move highlight str end, draw highlight, & restore
|
||||
restorechar = highlight[strlen(token)];
|
||||
highlight[strlen(token)] = '\0';
|
||||
if (indentx - (lrpad / 2) - 1 < maxw)
|
||||
drw_text(
|
||||
drw,
|
||||
x + indentx - (lrpad / 2) - 1,
|
||||
y,
|
||||
MIN(maxw - indentx, TEXTW(highlight) - lrpad),
|
||||
bh, 0, highlight, 0
|
||||
);
|
||||
highlight[strlen(token)] = restorechar;
|
||||
|
||||
if (strlen(highlight) - strlen(token) < strlen(token))
|
||||
break;
|
||||
highlight = fstrstr(highlight + strlen(token), token);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
#if CENTER_PATCH
|
||||
#include "center.c"
|
||||
#endif
|
||||
#if DYNAMIC_OPTIONS_PATCH
|
||||
#include "dynamicoptions.c"
|
||||
#endif
|
||||
#if FUZZYHIGHLIGHT_PATCH
|
||||
#include "fuzzyhighlight.c"
|
||||
#elif HIGHLIGHT_PATCH
|
||||
#include "highlight.c"
|
||||
#endif
|
||||
#if FUZZYMATCH_PATCH
|
||||
#include "fuzzymatch.c"
|
||||
#endif
|
||||
#if DYNAMIC_OPTIONS_PATCH
|
||||
#include "dynamicoptions.c"
|
||||
#endif
|
||||
#if MOUSE_SUPPORT_PATCH
|
||||
#include "mousesupport.c"
|
||||
#endif
|
||||
|
@ -57,6 +57,12 @@
|
||||
*/
|
||||
#define GRID_PATCH 0
|
||||
|
||||
/* This patch highlights the individual characters of matched text for each dmenu list entry.
|
||||
* The fuzzy highlight patch takes precedence over this patch.
|
||||
* https://tools.suckless.org/dmenu/patches/highlight/
|
||||
*/
|
||||
#define HIGHLIGHT_PATCH 0
|
||||
|
||||
/* This patch causes dmenu to print out the current text each time a key is pressed.
|
||||
* https://tools.suckless.org/dmenu/patches/incremental/
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user