[wiki] [sites] Add patch "highpriority" || takase1121

From: <git_AT_suckless.org>
Date: Sat, 16 May 2020 17:58:51 +0200

commit 9a3844c71548de8dcc902b2f822e799117b09997
Author: takase1121 <takase1121_AT_outlook.com>
Date: Sun May 17 07:57:44 2020 +0800

    Add patch "highpriority"
    
    This patch allows user to mark some programs as high-priority,
    thus showing up before others when searching.

diff --git a/tools.suckless.org/dmenu/patches/highpriority/dmenu-highpriority-4.9.diff b/tools.suckless.org/dmenu/patches/highpriority/dmenu-highpriority-4.9.diff
new file mode 100644
index 00000000..03e106ae
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/highpriority/dmenu-highpriority-4.9.diff
_AT_@ -0,0 +1,178 @@
+From e9e1691a9b4ffa2db45cd5108b76b9a68610ba37 Mon Sep 17 00:00:00 2001
+From: takase1121 <takase1121_AT_outlook.com>
+Date: Sun, 17 May 2020 07:05:32 +0800
+Subject: [PATCH] Adds high-priority items.
+
+This allows users to specify a list of high priority commands that should be
+displayed before other matches with the following arrangement:
+
+match -> prefix && high priority -> prefix -> substring
+
+As you can see, high priority for substring matches is not implemented or will not
+be implemented depending on needs.
+---
+ config.def.h | 1 +
+ dmenu.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++-----
+ 2 files changed, 59 insertions(+), 6 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1edb647..65e03fb 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -12,6 +12,7 @@ static const char *colors[SchemeLast][2] = {
+ [SchemeNorm] = { "#bbbbbb", "#222222" },
+ [SchemeSel] = { "#eeeeee", "#005577" },
+ [SchemeOut] = { "#000000", "#00ffff" },
++ [SchemeHp] = { "#bbbbbb", "#333333" }
+ };
+ /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
+ static unsigned int lines = 0;
+diff --git a/dmenu.c b/dmenu.c
+index 6b8f51b..7bf4099 100644
+--- a/dmenu.c
++++ b/dmenu.c
+_AT_@ -26,14 +26,16 @@
+ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+
+ /* enums */
+-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
++enum { SchemeNorm, SchemeSel, SchemeHp, SchemeOut, SchemeLast }; /* color schemes */
+
+ struct item {
+ char *text;
+ struct item *left, *right;
+- int out;
++ int out, hp;
+ };
+
++static char **hpitems = NULL;
++static int hplength = 0;
+ static char text[BUFSIZ] = "";
+ static char *embed;
+ static int bh, mw, mh;
+_AT_@ -58,6 +60,36 @@ static Clr *scheme[SchemeLast];
+ static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
+ static char *(*fstrstr)(const char *, const char *) = strstr;
+
++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
", sizeof(char*) * (listlength + 1));
++ if (!(list[listlength] = strdup(token)))
++ die("Unable to strdup %d bytes
", 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;
++}
++
+ static void
+ appenditem(struct item *item, struct item **list, struct item **last)
+ {
+_AT_@ -118,6 +150,8 @@ drawitem(struct item *item, int x, int y, int w)
+ {
+ if (item == sel)
+ drw_setscheme(drw, scheme[SchemeSel]);
++ else if (item->hp)
++ drw_setscheme(drw, scheme[SchemeHp]);
+ else if (item->out)
+ drw_setscheme(drw, scheme[SchemeOut]);
+ else
+_AT_@ -219,7 +253,7 @@ match(void)
+ char buf[sizeof text], *s;
+ int i, tokc = 0;
+ size_t len, textsize;
+- struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
++ struct item *item, *lhpprefix, *lprefix, *lsubstr, *hpprefixend, *prefixend, *substrend;
+
+ strcpy(buf, text);
+ /* separate input text into tokens to be matched individually */
+_AT_@ -228,7 +262,7 @@ match(void)
+ die("cannot realloc %u bytes:", tokn * sizeof *tokv);
+ len = tokc ? strlen(tokv[0]) : 0;
+
+- matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
++ matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL;
+ textsize = strlen(text) + 1;
+ for (item = items; item && item->text; item++) {
+ for (i = 0; i < tokc; i++)
+_AT_@ -236,14 +270,24 @@ match(void)
+ break;
+ if (i != tokc) /* not all tokens match */
+ continue;
+- /* exact matches go first, then prefixes, then substrings */
++ /* exact matches go first, then prefixes with high priority, then prefixes, then substrings */
+ if (!tokc || !fstrncmp(text, item->text, textsize))
+ appenditem(item, &matches, &matchend);
++ else if (item->hp && !fstrncmp(tokv[0], item->text, len))
++ appenditem(item, &lhpprefix, &hpprefixend);
+ else if (!fstrncmp(tokv[0], item->text, len))
+ appenditem(item, &lprefix, &prefixend);
+ else
+ appenditem(item, &lsubstr, &substrend);
+ }
++ if (lhpprefix) {
++ if (matches) {
++ matchend->right = lhpprefix;
++ lhpprefix->left = matchend;
++ } else
++ matches = lhpprefix;
++ matchend = hpprefixend;
++ }
+ if (lprefix) {
+ if (matches) {
+ matchend->right = lprefix;
+_AT_@ -535,6 +579,7 @@ readstdin(void)
+ if (!(items[i].text = strdup(buf)))
+ die("cannot strdup %u bytes:", strlen(buf) + 1);
+ items[i].out = 0;
++ items[i].hp = arrayhas(hpitems, hplength, items[i].text);
+ drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL);
+ if (tmpmax > inputw) {
+ inputw = tmpmax;
+_AT_@ -683,7 +728,8 @@ static void
+ usage(void)
+ {
+ fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]
"
+- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
", stderr);
++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
"
++ " [-hb color] [-hf color] [-hp items]
", stderr);
+ exit(1);
+ }
+
+_AT_@ -724,8 +770,14 @@ main(int argc, char *argv[])
+ colors[SchemeSel][ColBg] = argv[++i];
+ else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
+ colors[SchemeSel][ColFg] = argv[++i];
++ 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], "-w")) /* embedding window id */
+ embed = argv[++i];
++ else if (!strcmp(argv[i], "-hp"))
++ hpitems = tokenize(argv[++i], ",", &hplength);
+ else
+ usage();
+
+--
+2.26.2
+
diff --git a/tools.suckless.org/dmenu/patches/highpriority/dmenu-highpriority.gif b/tools.suckless.org/dmenu/patches/highpriority/dmenu-highpriority.gif
new file mode 100644
index 00000000..2923a75a
Binary files /dev/null and b/tools.suckless.org/dmenu/patches/highpriority/dmenu-highpriority.gif differ
diff --git a/tools.suckless.org/dmenu/patches/highpriority/index.md b/tools.suckless.org/dmenu/patches/highpriority/index.md
new file mode 100644
index 00000000..f59dceed
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/highpriority/index.md
_AT_@ -0,0 +1,25 @@
+highpriority
+============
+
+Description
+-----------
+This patch will automatically sort the search result so that high priority items are shown first.
+
+Adds the option *[SchemeHp]* to *colors* in config.def.h and the flags *hb*, *hf*, and *hp*.
+
+* *hb*: Background color of the high priority items
+* *hf*: Foreground color of the high priority items
+* *hp*: A CSV (comma-seperated list) of high priority items
+
+
+[![Screenshot dmenu with highpriority patch](dmenu-highpriority.gif)](dmenu-highpriority.gif)
+
+In this case, *chromium* is added to *hp* and it came first on search instead of *chromedriver*
+
+Download
+--------
+* [dmenu-highpriority-4.9.diff](dmenu-highpriority-4.9.diff)
+
+Author
+------
+* Takase
Received on Sat May 16 2020 - 17:58:51 CEST

This archive was generated by hypermail 2.3.0 : Sat May 16 2020 - 18:00:51 CEST