Adding highpriority patch

This commit is contained in:
bakkeby 2020-08-05 14:54:01 +02:00
parent aa50b3f2c5
commit 17d32014a3
7 changed files with 99 additions and 2 deletions

View File

@ -15,7 +15,7 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
### Changelog: ### Changelog:
2020-08-05 - Added the grid, highlight, dynamic options and numbers patches 2020-08-05 - Added the grid, highlight, highpriority, dynamic options and numbers patches
2020-06-13 - Added the pango patch 2020-06-13 - Added the pango patch
@ -67,6 +67,9 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
- [highlight](https://tools.suckless.org/dmenu/patches/highlight/) - [highlight](https://tools.suckless.org/dmenu/patches/highlight/)
- this patch highlights the individual characters of matched text for each dmenu list entry - this patch highlights the individual characters of matched text for each dmenu list entry
- [highpriority](https://tools.suckless.org/dmenu/patches/highpriority/)
- this patch will automatically sort the search result so that high priority items are shown first
- [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

View File

@ -60,6 +60,9 @@ static const char *colors[][2] =
[SchemeSelHighlight] = { "#ffc978", "#005577" }, [SchemeSelHighlight] = { "#ffc978", "#005577" },
[SchemeNormHighlight] = { "#ffc978", "#222222" }, [SchemeNormHighlight] = { "#ffc978", "#222222" },
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH #endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
#if HIGHPRIORITY_PATCH
[SchemeHp] = { "#bbbbbb", "#333333" },
#endif // HIGHPRIORITY_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;

50
dmenu.c
View File

@ -44,6 +44,9 @@ enum {
SchemeNormHighlight, SchemeNormHighlight,
SchemeSelHighlight, SchemeSelHighlight,
#endif // HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH #endif // HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH
#if HIGHPRIORITY_PATCH
SchemeHp,
#endif // HIGHPRIORITY_PATCH
SchemeLast, SchemeLast,
}; /* color schemes */ }; /* color schemes */
@ -54,6 +57,9 @@ struct item {
struct item *next; struct item *next;
#endif // NON_BLOCKING_STDIN_PATCH #endif // NON_BLOCKING_STDIN_PATCH
int out; int out;
#if HIGHPRIORITY_PATCH
int hp;
#endif // HIGHPRIORITY_PATCH
#if FUZZYMATCH_PATCH #if FUZZYMATCH_PATCH
double distance; double distance;
#endif // FUZZYMATCH_PATCH #endif // FUZZYMATCH_PATCH
@ -217,6 +223,10 @@ drawitem(struct item *item, int x, int y, int w)
int r; int r;
if (item == sel) if (item == sel)
drw_setscheme(drw, scheme[SchemeSel]); drw_setscheme(drw, scheme[SchemeSel]);
#if HIGHPRIORITY_PATCH
else if (item->hp)
drw_setscheme(drw, scheme[SchemeHp]);
#endif // HIGHPRIORITY_PATCH
else if (item->out) else if (item->out)
drw_setscheme(drw, scheme[SchemeOut]); drw_setscheme(drw, scheme[SchemeOut]);
else else
@ -470,6 +480,9 @@ match(void)
int i, tokc = 0; int i, tokc = 0;
size_t len, textsize; size_t len, textsize;
struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
#if HIGHPRIORITY_PATCH
struct item *lhpprefix, *hpprefixend;
#endif // HIGHPRIORITY_PATCH
#if NON_BLOCKING_STDIN_PATCH #if NON_BLOCKING_STDIN_PATCH
int preserve = 0; int preserve = 0;
#endif // NON_BLOCKING_STDIN_PATCH #endif // NON_BLOCKING_STDIN_PATCH
@ -493,6 +506,9 @@ match(void)
matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
textsize = strlen(text) + 1; textsize = strlen(text) + 1;
#endif // PREFIXCOMPLETION_PATCH #endif // PREFIXCOMPLETION_PATCH
#if HIGHPRIORITY_PATCH
lhpprefix = hpprefixend = NULL;
#endif // HIGHPRIORITY_PATCH
#if NON_BLOCKING_STDIN_PATCH #if NON_BLOCKING_STDIN_PATCH
for (item = items; item; item = item->next) for (item = items; item; item = item->next)
#else #else
@ -509,9 +525,17 @@ match(void)
if (i != tokc) /* not all tokens match */ if (i != tokc) /* not all tokens match */
continue; continue;
#endif // DYNAMIC_OPTIONS_PATCH #endif // DYNAMIC_OPTIONS_PATCH
#if HIGHPRIORITY_PATCH
/* exact matches go first, then prefixes with high priority, then prefixes, then substrings */
#else
/* exact matches go first, then prefixes, then substrings */ /* exact matches go first, then prefixes, then substrings */
#endif // HIGHPRIORITY_PATCH
if (!tokc || !fstrncmp(text, item->text, textsize)) if (!tokc || !fstrncmp(text, item->text, textsize))
appenditem(item, &matches, &matchend); appenditem(item, &matches, &matchend);
#if HIGHPRIORITY_PATCH
else if (item->hp && !fstrncmp(tokv[0], item->text, len))
appenditem(item, &lhpprefix, &hpprefixend);
#endif // HIGHPRIORITY_PATCH
else if (!fstrncmp(tokv[0], item->text, len)) else if (!fstrncmp(tokv[0], item->text, len))
appenditem(item, &lprefix, &prefixend); appenditem(item, &lprefix, &prefixend);
#if PREFIXCOMPLETION_PATCH #if PREFIXCOMPLETION_PATCH
@ -525,6 +549,16 @@ match(void)
preserve = 1; preserve = 1;
#endif // NON_BLOCKING_STDIN_PATCH #endif // NON_BLOCKING_STDIN_PATCH
} }
#if HIGHPRIORITY_PATCH
if (lhpprefix) {
if (matches) {
matchend->right = lhpprefix;
lhpprefix->left = matchend;
} else
matches = lhpprefix;
matchend = hpprefixend;
}
#endif // HIGHPRIORITY_PATCH
if (lprefix) { if (lprefix) {
if (matches) { if (matches) {
matchend->right = lprefix; matchend->right = lprefix;
@ -958,6 +992,9 @@ readstdin(void)
if (!(items[i].text = strdup(buf))) if (!(items[i].text = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1); die("cannot strdup %u bytes:", strlen(buf) + 1);
items[i].out = 0; items[i].out = 0;
#if HIGHPRIORITY_PATCH
items[i].hp = arrayhas(hpitems, hplength, items[i].text);
#endif // HIGHPRIORITY_PATCH
#if PANGO_PATCH #if PANGO_PATCH
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True); drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
#else #else
@ -1278,7 +1315,7 @@ usage(void)
#endif // GRID_PATCH #endif // GRID_PATCH
"[-l lines] [-p prompt] [-fn font] [-m monitor]" "[-l lines] [-p prompt] [-fn font] [-m monitor]"
"\n [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]" "\n [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"
#if ALPHA_PATCH || BORDER_PATCH || INITIALTEXT_PATCH || LINE_HEIGHT_PATCH || NAVHISTORY_PATCH || XYW_PATCH || DYNAMIC_OPTIONS_PATCH #if ALPHA_PATCH || BORDER_PATCH || HIGHPRIORITY_PATCH || INITIALTEXT_PATCH || LINE_HEIGHT_PATCH || NAVHISTORY_PATCH || XYW_PATCH || DYNAMIC_OPTIONS_PATCH
"\n " "\n "
#endif #endif
#if DYNAMIC_OPTIONS_PATCH #if DYNAMIC_OPTIONS_PATCH
@ -1290,6 +1327,9 @@ usage(void)
#if BORDER_PATCH #if BORDER_PATCH
" [-bw width]" " [-bw width]"
#endif // BORDER_PATCH #endif // BORDER_PATCH
#if HIGHPRIORITY_PATCH
" [-hb color] [-hf color] [-hp items]"
#endif // HIGHPRIORITY_PATCH
#if INITIALTEXT_PATCH #if INITIALTEXT_PATCH
" [-it text]" " [-it text]"
#endif // INITIALTEXT_PATCH #endif // INITIALTEXT_PATCH
@ -1422,6 +1462,14 @@ 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 HIGHPRIORITY_PATCH
else if (!strcmp(argv[i], "-hb")) /* high priority background color */
colors[SchemeHp][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-hf")) /* low priority background color */
colors[SchemeHp][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-hp"))
hpitems = tokenize(argv[++i], ",", &hplength);
#endif // HIGHPRIORITY_PATCH
#if HIGHLIGHT_PATCH || 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];

View File

@ -34,6 +34,9 @@ readstream(FILE* stream)
if (!(items[i].text = strdup(buf))) if (!(items[i].text = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1); die("cannot strdup %u bytes:", strlen(buf) + 1);
items[i].out = 0; items[i].out = 0;
#if HIGHPRIORITY_PATCH
items[i].hp = arrayhas(hpitems, hplength, items[i].text);
#endif // HIGHPRIORITY_PATCH
#if PANGO_PATCH #if PANGO_PATCH
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True); drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
#else #else

32
patch/highpriority.c Normal file
View File

@ -0,0 +1,32 @@
static char **hpitems = NULL;
static int hplength = 0;
static char**
tokenize(char *source, const char *delim, int *llen) {
int listlength = 0;
char **list = malloc(1 * sizeof(char*));
char *token = strtok(source, delim);
while (token) {
if (!(list = realloc(list, sizeof(char*) * (listlength + 1))))
die("Unable to realloc %d bytes\n", sizeof(char*) * (listlength + 1));
if (!(list[listlength] = strdup(token)))
die("Unable to strdup %d bytes\n", strlen(token) + 1);
token = strtok(NULL, delim);
listlength++;
}
*llen = listlength;
return list;
}
static int
arrayhas(char **list, int length, char *item) {
for (int i = 0; i < length; i++) {
int len1 = strlen(list[i]);
int len2 = strlen(item);
if (fstrncmp(list[i], item, len1 > len2 ? len2 : len1) == 0)
return 1;
}
return 0;
}

View File

@ -12,6 +12,9 @@
#if FUZZYMATCH_PATCH #if FUZZYMATCH_PATCH
#include "fuzzymatch.c" #include "fuzzymatch.c"
#endif #endif
#if HIGHPRIORITY_PATCH
#include "highpriority.c"
#endif
#if MOUSE_SUPPORT_PATCH #if MOUSE_SUPPORT_PATCH
#include "mousesupport.c" #include "mousesupport.c"
#endif #endif

View File

@ -63,6 +63,11 @@
*/ */
#define HIGHLIGHT_PATCH 0 #define HIGHLIGHT_PATCH 0
/* This will automatically sort the search result so that high priority items are shown first.
* https://tools.suckless.org/dmenu/patches/highpriority/
*/
#define HIGHPRIORITY_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/
*/ */