sites

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

dmenu-incremental-20160702-3c91eed.diff (2277B)


      1 From 38914e7a39b12ba1001b5464e6d96d1d15e73634 Mon Sep 17 00:00:00 2001
      2 From: Hiltjo Posthuma <hiltjo@codemadness.org>
      3 Date: Fri, 17 Jun 2016 15:33:50 +0200
      4 Subject: [PATCH] incremental mode: dmenu outputs text each time a key is
      5  pressed.
      6 
      7 ---
      8  config.def.h | 1 +
      9  dmenu.1      | 4 ++++
     10  dmenu.c      | 8 +++++++-
     11  3 files changed, 12 insertions(+), 1 deletion(-)
     12 
     13 diff --git a/config.def.h b/config.def.h
     14 index dcffd38..994f3a5 100644
     15 --- a/config.def.h
     16 +++ b/config.def.h
     17 @@ -2,6 +2,7 @@
     18  /* Default settings; can be overriden by command line. */
     19  
     20  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
     21 +static int incremental = 0;                 /* -r  option; if 1, outputs text each time a key is pressed */
     22  /* -fn option overrides fonts[0]; default X11 font or font set */
     23  static const char *fonts[] = {
     24  	"monospace:size=10"
     25 diff --git a/dmenu.1 b/dmenu.1
     26 index d3ab805..e5bf42f 100644
     27 --- a/dmenu.1
     28 +++ b/dmenu.1
     29 @@ -18,6 +18,7 @@ dmenu \- dynamic menu
     30  .IR color ]
     31  .RB [ \-nf
     32  .IR color ]
     33 +.RB [ \-r ]
     34  .RB [ \-sb
     35  .IR color ]
     36  .RB [ \-sf
     37 @@ -58,6 +59,9 @@ from 0.
     38  .BI \-p " prompt"
     39  defines the prompt to be displayed to the left of the input field.
     40  .TP
     41 +.B \-r
     42 +dmenu outputs text each time a key is pressed.
     43 +.TP
     44  .BI \-fn " font"
     45  defines the font or font set used.
     46  .TP
     47 diff --git a/dmenu.c b/dmenu.c
     48 index e0c2f80..7f1be56 100644
     49 --- a/dmenu.c
     50 +++ b/dmenu.c
     51 @@ -447,6 +447,10 @@ keypress(XKeyEvent *ev)
     52  		match();
     53  		break;
     54  	}
     55 +	if (incremental) {
     56 +		puts(text);
     57 +		fflush(stdout);
     58 +	}
     59  	drawmenu();
     60  }
     61  
     62 @@ -611,7 +615,7 @@ static void
     63  usage(void)
     64  {
     65  	fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     66 -	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
     67 +	      "             [-nb color] [-nf color] [-r] [-sb color] [-sf color] [-v]\n", stderr);
     68  	exit(1);
     69  }
     70  
     71 @@ -629,6 +633,8 @@ main(int argc, char *argv[])
     72  			topbar = 0;
     73  		else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */
     74  			fast = 1;
     75 +		else if (!strcmp(argv[i], "-r"))   /* incremental */
     76 +			incremental = 1;
     77  		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
     78  			fstrncmp = strncasecmp;
     79  			fstrstr = cistrstr;
     80 -- 
     81 2.8.3
     82