sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 193f2148224a1be13cf5ad5f6ed8b7efb259e600
parent 8825492293097aed5204104ac961e2cd3d303258
Author: koniu <koniu@riseup.net>
Date:   Wed, 15 Jun 2016 13:06:31 +0100

[tools/dmenu] update several patches to git master

Diffstat:
Atools.suckless.org/dmenu/patches/dmenu-git-incremental.diff | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/dmenu-git-instant.diff | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/dmenu-git-non-blocking-stdin.diff | 247+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools.suckless.org/dmenu/patches/incremental.md | 1+
Mtools.suckless.org/dmenu/patches/instant.md | 1+
Mtools.suckless.org/dmenu/patches/non_blocking_stdin.md | 5++---
6 files changed, 393 insertions(+), 3 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/dmenu-git-incremental.diff b/tools.suckless.org/dmenu/patches/dmenu-git-incremental.diff @@ -0,0 +1,70 @@ +diff --git a/config.def.h b/config.def.h +index dcffd38..b879e9f 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -2,6 +2,7 @@ + /* Default settings; can be overriden by command line. */ + + static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ ++static int incremental = 0; /* -r option; if 1, dmenu outputs during input */ + /* -fn option overrides fonts[0]; default X11 font or font set */ + static const char *fonts[] = { + "monospace:size=10" +diff --git a/dmenu.1 b/dmenu.1 +index d3ab805..044f955 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -6,6 +6,7 @@ dmenu \- dynamic menu + .RB [ \-b ] + .RB [ \-f ] + .RB [ \-i ] ++.RB [ \-r ] + .RB [ \-l + .RB [ \-m + .IR monitor ] +@@ -48,6 +49,9 @@ X until stdin reaches end\-of\-file. + .B \-i + dmenu matches menu items case insensitively. + .TP ++.B \-r ++dmenu outputs text each time a key is pressed. ++.TP + .BI \-l " lines" + dmenu lists items vertically, with the given number of lines. + .TP +diff --git a/dmenu.c b/dmenu.c +index e0c2f80..100ab10 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -447,6 +447,11 @@ keypress(XKeyEvent *ev) + match(); + break; + } ++ if(incremental) { ++ fprintf(stdout, "%s\n", text); ++ fflush(stdout); ++ } ++ + drawmenu(); + } + +@@ -610,7 +615,7 @@ setup(void) + static void + usage(void) + { +- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" ++ fputs("usage: dmenu [-b] [-f] [-i] [-r] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); + exit(1); + } +@@ -632,7 +637,9 @@ main(int argc, char *argv[]) + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +- } else if (i + 1 == argc) ++ } else if (!strcmp(argv[i], "-r")) /* outputs during input */ ++ incremental = 1; ++ else if (i + 1 == argc) + usage(); + /* these options take one argument */ + else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ diff --git a/tools.suckless.org/dmenu/patches/dmenu-git-instant.diff b/tools.suckless.org/dmenu/patches/dmenu-git-instant.diff @@ -0,0 +1,72 @@ +diff --git a/config.def.h b/config.def.h +index dcffd38..a42d28b 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -1,6 +1,7 @@ + /* See LICENSE file for copyright and license details. */ + /* Default settings; can be overriden by command line. */ + ++static int instant = 0; + static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ + /* -fn option overrides fonts[0]; default X11 font or font set */ + static const char *fonts[] = { +diff --git a/dmenu.1 b/dmenu.1 +index d3ab805..8806d4d 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -6,6 +6,7 @@ dmenu \- dynamic menu + .RB [ \-b ] + .RB [ \-f ] + .RB [ \-i ] ++.RB [ \-n ] + .RB [ \-l + .RB [ \-m + .IR monitor ] +@@ -48,6 +49,9 @@ X until stdin reaches end\-of\-file. + .B \-i + dmenu matches menu items case insensitively. + .TP ++.B \-n ++dmenu instantly selects if only one match. ++.TP + .BI \-l " lines" + dmenu lists items vertically, with the given number of lines. + .TP +diff --git a/dmenu.c b/dmenu.c +index e0c2f80..f079479 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -250,6 +250,13 @@ match(void) + matchend = substrend; + } + curr = sel = matches; ++ ++ if(instant && matches && matches==matchend && !lsubstr) { ++ puts(matches->text); ++ cleanup(); ++ exit(0); ++ } ++ + calcoffsets(); + } + +@@ -610,7 +617,7 @@ setup(void) + static void + usage(void) + { +- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" ++ fputs("usage: dmenu [-b] [-f] [-i] [-n] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); + exit(1); + } +@@ -632,7 +639,9 @@ main(int argc, char *argv[]) + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +- } else if (i + 1 == argc) ++ } else if (!strcmp(argv[i], "-n")) /* instant select only match */ ++ instant = 1; ++ else if (i + 1 == argc) + usage(); + /* these options take one argument */ + else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ diff --git a/tools.suckless.org/dmenu/patches/dmenu-git-non-blocking-stdin.diff b/tools.suckless.org/dmenu/patches/dmenu-git-non-blocking-stdin.diff @@ -0,0 +1,247 @@ +diff --git a/dmenu.1 b/dmenu.1 +index d3ab805..00958cf 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -4,7 +4,6 @@ dmenu \- dynamic menu + .SH SYNOPSIS + .B dmenu + .RB [ \-b ] +-.RB [ \-f ] + .RB [ \-i ] + .RB [ \-l + .RB [ \-m +@@ -41,10 +40,6 @@ which lists programs in the user's $PATH and runs the result in their $SHELL. + .B \-b + dmenu appears at the bottom of the screen. + .TP +-.B \-f +-dmenu grabs the keyboard before reading stdin. This is faster, but will lock up +-X until stdin reaches end\-of\-file. +-.TP + .B \-i + dmenu matches menu items case insensitively. + .TP +diff --git a/dmenu.c b/dmenu.c +index e0c2f80..f819d67 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -1,12 +1,15 @@ + /* See LICENSE file for copyright and license details. */ + #include <ctype.h> ++#include <fcntl.h> + #include <locale.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include <strings.h> + #include <time.h> ++#include <unistd.h> + ++#include <sys/select.h> + #include <X11/Xlib.h> + #include <X11/Xatom.h> + #include <X11/Xutil.h> +@@ -31,6 +34,7 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ + struct item { + char *text; + struct item *left, *right; ++ struct item *next; + int out; + }; + +@@ -181,6 +185,7 @@ drawmenu(void) + } + } + drw_map(drw, win, 0, 0, mw, mh); ++ XFlush(dpy); + } + + static void +@@ -209,6 +214,7 @@ match(void) + int i, tokc = 0; + size_t len, textsize; + struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; ++ int preserve = 0; + + strcpy(buf, text); + /* separate input text into tokens to be matched individually */ +@@ -219,19 +225,24 @@ match(void) + + matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; + textsize = strlen(text); +- for (item = items; item && item->text; item++) { ++ ++ for (item = items; item; item = item->next) { + for (i = 0; i < tokc; i++) + if (!fstrstr(item->text, tokv[i])) + break; + if (i != tokc) /* not all tokens match */ + continue; + /* exact matches go first, then prefixes, then substrings */ +- if (!tokc || !fstrncmp(text, item->text, textsize)) ++ if (!tokc || !fstrncmp(text, item->text, textsize)) { + appenditem(item, &matches, &matchend); +- else if (!fstrncmp(tokv[0], item->text, len)) ++ if (sel == item) preserve = 1; ++ } else if (!fstrncmp(tokv[0], item->text, len)) { + appenditem(item, &lprefix, &prefixend); +- else ++ if (sel == item) preserve = 1; ++ } else { + appenditem(item, &lsubstr, &substrend); ++ if (sel == item) preserve = 1; ++ } + } + if (lprefix) { + if (matches) { +@@ -249,7 +260,9 @@ match(void) + matches = lsubstr; + matchend = substrend; + } +- curr = sel = matches; ++ if (!preserve) ++ curr = sel = matches; ++ + calcoffsets(); + } + +@@ -467,36 +480,11 @@ paste(void) + } + + static void +-readstdin(void) +-{ +- char buf[sizeof text], *p, *maxstr = NULL; +- size_t i, max = 0, size = 0; +- +- /* read each line from stdin and add it to the item list */ +- for (i = 0; fgets(buf, sizeof buf, stdin); i++) { +- if (i + 1 >= size / sizeof *items) +- if (!(items = realloc(items, (size += BUFSIZ)))) +- die("cannot realloc %u bytes:", size); +- if ((p = strchr(buf, '\n'))) +- *p = '\0'; +- if (!(items[i].text = strdup(buf))) +- die("cannot strdup %u bytes:", strlen(buf) + 1); +- items[i].out = 0; +- if (strlen(items[i].text) > max) +- max = strlen(maxstr = items[i].text); +- } +- if (items) +- items[i].text = NULL; +- inputw = maxstr ? TEXTW(maxstr) : 0; +- lines = MIN(lines, i); +-} +- +-static void +-run(void) ++readevent(void) + { + XEvent ev; + +- while (!XNextEvent(dpy, &ev)) { ++ while(XPending(dpy) && !XNextEvent(dpy, &ev)) { + if (XFilterEvent(&ev, win)) + continue; + switch(ev.type) { +@@ -520,6 +508,58 @@ run(void) + } + + static void ++readstdin(void) { ++ static size_t max = 0; ++ static struct item **end = &items; ++ ++ char buf[sizeof text], *p, *maxstr; ++ struct item *item; ++ ++ /* read each line from stdin and add it to the item list */ ++ while(fgets(buf, sizeof buf, stdin)) { ++ if(!(item = malloc(sizeof *item))) ++ die("cannot malloc %u bytes:", sizeof *item); ++ if((p = strchr(buf, '\n'))) ++ *p = '\0'; ++ if(!(item->text = strdup(buf))) ++ die("cannot strdup %u bytes:", strlen(buf)+1); ++ if(strlen(item->text) > max) { ++ max = strlen(maxstr = item->text); ++ inputw = maxstr ? TEXTW(maxstr) : 0; ++ } ++ *end = item; ++ end = &item->next; ++ item->next = NULL; ++ item->out = 0; ++ } ++ match(); ++ drawmenu(); ++} ++ ++static void ++run(void) { ++ fd_set fds; ++ int flags, xfd = XConnectionNumber(dpy); ++ ++ if((flags = fcntl(STDIN_FILENO, F_GETFL)) == -1) ++ die("cannot get stdin control flags:"); ++ if(fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK) == -1) ++ die("cannot set stdin control flags:"); ++ for(;;) { ++ FD_ZERO(&fds); ++ FD_SET(xfd, &fds); ++ if(!feof(stdin)) ++ FD_SET(STDIN_FILENO, &fds); ++ if(select(MAX(STDIN_FILENO, xfd) + 1, &fds, NULL, NULL, NULL) == -1) ++ die("cannot multiplex input:"); ++ if(FD_ISSET(xfd, &fds)) ++ readevent(); ++ if(FD_ISSET(STDIN_FILENO, &fds)) ++ readstdin(); ++ } ++} ++ ++static void + setup(void) + { + int x, y; +@@ -610,7 +650,7 @@ setup(void) + static void + usage(void) + { +- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" ++ fputs("usage: dmenu [-b] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); + exit(1); + } +@@ -618,7 +658,7 @@ usage(void) + int + main(int argc, char *argv[]) + { +- int i, fast = 0; ++ int i; + + for (i = 1; i < argc; i++) + /* these options take no arguments */ +@@ -627,8 +667,6 @@ main(int argc, char *argv[]) + exit(0); + } else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ + topbar = 0; +- else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ +- fast = 1; + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +@@ -668,13 +706,7 @@ main(int argc, char *argv[]) + die("no fonts could be loaded.\n"); + drw_setscheme(drw, &scheme[SchemeNorm]); + +- if (fast) { +- grabkeyboard(); +- readstdin(); +- } else { +- readstdin(); +- grabkeyboard(); +- } ++ grabkeyboard(); + setup(); + run(); + diff --git a/tools.suckless.org/dmenu/patches/incremental.md b/tools.suckless.org/dmenu/patches/incremental.md @@ -15,3 +15,4 @@ Download -------- * [dmenu-tip-incremental.diff](dmenu-tip-incremental.diff) +* [dmenu-git-incremental.diff](dmenu-git-incremental.diff) diff --git a/tools.suckless.org/dmenu/patches/instant.md b/tools.suckless.org/dmenu/patches/instant.md @@ -6,6 +6,7 @@ Adds an flag which will cause dmenu to select an item immediately if theres one Download -------- * [dmenu-instant.diff](dmenu-instant.diff) +* [dmenu-git-instant.diff](dmenu-git-instant.diff) Author ------ diff --git a/tools.suckless.org/dmenu/patches/non_blocking_stdin.md b/tools.suckless.org/dmenu/patches/non_blocking_stdin.md @@ -12,12 +12,11 @@ patch, so that you can use stdout to feed stdin. Download -------- -This patch should apply on git version 2b9683c50723 (the latest - -2010-12-08) - * [dmenu-tip-non-blocking-stdin.diff](dmenu-tip-non-blocking-stdin.diff) +* [dmenu-git-non-blocking-stdin.diff](dmenu-git-non-blocking-stdin.diff) Author ------ * Christophe-Marie Duquesne <chm.duquesne@gmail.com> +* koniu at riseup.net (update for 20160615 git master)