mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 12:05:48 +00: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:
|
### 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
|
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
|
- 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
|
- 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/)
|
- [incremental](https://tools.suckless.org/dmenu/patches/incremental/)
|
||||||
- this patch causes dmenu to print out the current text each time a key is pressed
|
- 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" },
|
[SchemeNorm] = { "#bbbbbb", "#222222" },
|
||||||
[SchemeSel] = { "#eeeeee", "#005577" },
|
[SchemeSel] = { "#eeeeee", "#005577" },
|
||||||
[SchemeOut] = { "#000000", "#00ffff" },
|
[SchemeOut] = { "#000000", "#00ffff" },
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||||
[SchemeSelHighlight] = { "#ffc978", "#005577" },
|
[SchemeSelHighlight] = { "#ffc978", "#005577" },
|
||||||
[SchemeNormHighlight] = { "#ffc978", "#222222" },
|
[SchemeNormHighlight] = { "#ffc978", "#222222" },
|
||||||
#endif // FUZZYHIGHLIGHT_PATCH
|
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||||
};
|
};
|
||||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
static unsigned int lines = 0;
|
static unsigned int lines = 0;
|
||||||
|
22
dmenu.c
22
dmenu.c
@ -40,10 +40,10 @@ enum {
|
|||||||
SchemeNorm,
|
SchemeNorm,
|
||||||
SchemeSel,
|
SchemeSel,
|
||||||
SchemeOut,
|
SchemeOut,
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||||
SchemeNormHighlight,
|
SchemeNormHighlight,
|
||||||
SchemeSelHighlight,
|
SchemeSelHighlight,
|
||||||
#endif // FUZZYHIGHLIGHT_PATCH
|
#endif // HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||||
SchemeLast,
|
SchemeLast,
|
||||||
}; /* color schemes */
|
}; /* color schemes */
|
||||||
|
|
||||||
@ -214,9 +214,7 @@ cistrstr(const char *s, const char *sub)
|
|||||||
static int
|
static int
|
||||||
drawitem(struct item *item, int x, int y, int w)
|
drawitem(struct item *item, int x, int y, int w)
|
||||||
{
|
{
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
|
||||||
int r;
|
int r;
|
||||||
#endif // FUZZYHIGHLIGHT_PATCH
|
|
||||||
if (item == sel)
|
if (item == sel)
|
||||||
drw_setscheme(drw, scheme[SchemeSel]);
|
drw_setscheme(drw, scheme[SchemeSel]);
|
||||||
else if (item->out)
|
else if (item->out)
|
||||||
@ -224,19 +222,15 @@ drawitem(struct item *item, int x, int y, int w)
|
|||||||
else
|
else
|
||||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||||
|
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
|
||||||
#if PANGO_PATCH
|
#if PANGO_PATCH
|
||||||
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0, True);
|
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0, True);
|
||||||
#else
|
#else
|
||||||
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||||
#endif // PANGO_PATCH
|
#endif // PANGO_PATCH
|
||||||
|
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||||
drawhighlights(item, x, y, w);
|
drawhighlights(item, x, y, w);
|
||||||
|
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||||
return r;
|
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
|
static void
|
||||||
@ -1308,9 +1302,9 @@ usage(void)
|
|||||||
#if XYW_PATCH
|
#if XYW_PATCH
|
||||||
" [-X xoffset] [-Y yoffset] [-W width]" // (arguments made upper case due to conflicts)
|
" [-X xoffset] [-Y yoffset] [-W width]" // (arguments made upper case due to conflicts)
|
||||||
#endif // XYW_PATCH
|
#endif // XYW_PATCH
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||||
"\n [-nhb color] [-nhf color] [-shb color] [-shf color]" // highlight colors
|
"\n [-nhb color] [-nhf color] [-shb color] [-shf color]" // highlight colors
|
||||||
#endif // FUZZYHIGHLIGHT_PATCH
|
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||||
"\n", stderr);
|
"\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1428,7 +1422,7 @@ main(int argc, char *argv[])
|
|||||||
colors[SchemeSel][ColBg] = argv[++i];
|
colors[SchemeSel][ColBg] = argv[++i];
|
||||||
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
|
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
|
||||||
colors[SchemeSel][ColFg] = argv[++i];
|
colors[SchemeSel][ColFg] = argv[++i];
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
#if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
|
||||||
else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
|
else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
|
||||||
colors[SchemeNormHighlight][ColBg] = argv[++i];
|
colors[SchemeNormHighlight][ColBg] = argv[++i];
|
||||||
else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
|
else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
|
||||||
@ -1437,7 +1431,7 @@ main(int argc, char *argv[])
|
|||||||
colors[SchemeSelHighlight][ColBg] = argv[++i];
|
colors[SchemeSelHighlight][ColBg] = argv[++i];
|
||||||
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
|
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
|
||||||
colors[SchemeSelHighlight][ColFg] = argv[++i];
|
colors[SchemeSelHighlight][ColFg] = argv[++i];
|
||||||
#endif // FUZZYHIGHLIGHT_PATCH
|
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
|
||||||
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||||
embed = argv[++i];
|
embed = argv[++i];
|
||||||
#if DYNAMIC_OPTIONS_PATCH
|
#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
|
#if CENTER_PATCH
|
||||||
#include "center.c"
|
#include "center.c"
|
||||||
#endif
|
#endif
|
||||||
|
#if DYNAMIC_OPTIONS_PATCH
|
||||||
|
#include "dynamicoptions.c"
|
||||||
|
#endif
|
||||||
#if FUZZYHIGHLIGHT_PATCH
|
#if FUZZYHIGHLIGHT_PATCH
|
||||||
#include "fuzzyhighlight.c"
|
#include "fuzzyhighlight.c"
|
||||||
|
#elif HIGHLIGHT_PATCH
|
||||||
|
#include "highlight.c"
|
||||||
#endif
|
#endif
|
||||||
#if FUZZYMATCH_PATCH
|
#if FUZZYMATCH_PATCH
|
||||||
#include "fuzzymatch.c"
|
#include "fuzzymatch.c"
|
||||||
#endif
|
#endif
|
||||||
#if DYNAMIC_OPTIONS_PATCH
|
|
||||||
#include "dynamicoptions.c"
|
|
||||||
#endif
|
|
||||||
#if MOUSE_SUPPORT_PATCH
|
#if MOUSE_SUPPORT_PATCH
|
||||||
#include "mousesupport.c"
|
#include "mousesupport.c"
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +57,12 @@
|
|||||||
*/
|
*/
|
||||||
#define GRID_PATCH 0
|
#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.
|
/* This patch causes dmenu to print out the current text each time a key is pressed.
|
||||||
* https://tools.suckless.org/dmenu/patches/incremental/
|
* https://tools.suckless.org/dmenu/patches/incremental/
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user