Return to repo list

suckless-gf-dmenu

Gentoo-friendly patches for Suckless's dmenu.
Return to HMagellan.com

commit 3ff7a30ab52ee9754dd7cf2accca7e000d6847a8
parent 91cf37d990c735956429cb6a0be5e26cd12a3403
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 15 Aug 2020 17:34:33 -0500

Added dynamicoptions

Diffstat:
Apatches/dynamicoptions/USAGE | 33+++++++++++++++++++++++++++++++++
Apatches/dynamicoptions/dynamicoptions.patch | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/patches/dynamicoptions/USAGE b/patches/dynamicoptions/USAGE @@ -0,0 +1,33 @@ +dynamicoptions - Dynamic options for dmenu +Source: https://tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-01e2dfc7.diff +Original Author: ttmx - tiago.sequeira.teles@gmail.com + +Description from source: + """ + This patch adds a flag (-dy) which makes dmenu run the command given to it whenever input is changed with the + current input as the last argument and update the option list according to the output of that command. + + By default dmenu does not let you change the option list after starting it, this patch adds support for that. + It is best used with the -l flag. + + (ie. usage: dmenu -dy ls runs ls on whatever directory/file you are currently typing in dmenu and lets you + select it) + """ + +== YOU MUST == +(1). Place the patch file in /etc/portage/patches/x11-misc/dmenu/ +(2). Add the following line to your savedconfig file: + + static const char *dynamic = NULL; + + This variable represents the dynamic command to run on input change. +(3). Run 'emerge dmenu' + +== YOU PROBABLY SHOULD == +(1). Run dmenu with the '-dy X' option, where 'X' is some command to run whenever dmenu's input is changed. + +== PATCH MODIFICATIONS == +(1). Removed lines relating to config.def.h + +== INCOMPATIBILITIES == +No known specific incompatibilities. diff --git a/patches/dynamicoptions/dynamicoptions.patch b/patches/dynamicoptions/dynamicoptions.patch @@ -0,0 +1,109 @@ +diff --git a/dmenu.c b/dmenu.c +index 6b8f51b5..356d4cc9 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -210,9 +210,33 @@ grabkeyboard(void) + die("cannot grab keyboard"); + } + ++static void readstdin(FILE* stream); ++ ++static void ++refreshoptions(){ ++ int dynlen = strlen(dynamic); ++ char* cmd= malloc(dynlen + strlen(text)+2); ++ if(cmd == NULL) ++ die("malloc:"); ++ sprintf(cmd,"%s %s",dynamic, text); ++ FILE *stream = popen(cmd, "r"); ++ if(!stream) ++ die("popen(%s):",cmd); ++ readstdin(stream); ++ int pc = pclose(stream); ++ if(pc == -1) ++ die("pclose:"); ++ free(cmd); ++ curr = sel = items; ++} ++ + static void + match(void) + { ++ if(dynamic && *dynamic){ ++ refreshoptions(); ++ } ++ + static char **tokv = NULL; + static int tokn = 0; + +@@ -234,7 +258,7 @@ match(void) + for (i = 0; i < tokc; i++) + if (!fstrstr(item->text, tokv[i])) + break; +- if (i != tokc) /* not all tokens match */ ++ if (i != tokc && !(dynamic && *dynamic)) /* not all tokens match */ + continue; + /* exact matches go first, then prefixes, then substrings */ + if (!tokc || !fstrncmp(text, item->text, textsize)) +@@ -519,14 +543,14 @@ paste(void) + } + + static void +-readstdin(void) ++readstdin(FILE* stream) + { + char buf[sizeof text], *p; + size_t i, imax = 0, size = 0; + unsigned int tmpmax = 0; + + /* read each line from stdin and add it to the item list */ +- for (i = 0; fgets(buf, sizeof buf, stdin); i++) { ++ for (i = 0; fgets(buf, sizeof buf, stream); i++) { + if (i + 1 >= size / sizeof *items) + if (!(items = realloc(items, (size += BUFSIZ)))) + die("cannot realloc %u bytes:", size); +@@ -544,7 +568,8 @@ readstdin(void) + if (items) + items[i].text = NULL; + inputw = items ? TEXTW(items[imax].text) : 0; +- lines = MIN(lines, i); ++ if (!dynamic || !*dynamic) ++ lines = MIN(lines, i); + } + + static void +@@ -683,7 +708,7 @@ static void + usage(void) + { + fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" +- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); ++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n" "[-dy command]\n", stderr); + exit(1); + } + +@@ -726,6 +751,8 @@ main(int argc, char *argv[]) + colors[SchemeSel][ColFg] = argv[++i]; + else if (!strcmp(argv[i], "-w")) /* embedding window id */ + embed = argv[++i]; ++ else if (!strcmp(argv[i], "-dy")) /* dynamic command to run */ ++ dynamic = argv[++i]; + else + usage(); + +@@ -754,9 +781,11 @@ main(int argc, char *argv[]) + + if (fast && !isatty(0)) { + grabkeyboard(); +- readstdin(); ++ if(!(dynamic && *dynamic)) ++ readstdin(stdin); + } else { +- readstdin(); ++ if(!(dynamic && *dynamic)) ++ readstdin(stdin); + grabkeyboard(); + } + setup(); +-- +2.26.2 +