dmenu

Mahdi's build of dmenu
git clone git://mahdi.pw/dmenu.git
Log | Files | Refs | README | LICENSE

dmenu-preselect-20200513-db6093f.diff (2390B)


      1 From 055e86dee88c5135b3d3a691942a915334d1b3a2 Mon Sep 17 00:00:00 2001
      2 From: Mathieu Moneyron <[email protected]>
      3 Date: Wed, 13 May 2020 17:28:37 +0200
      4 Subject: [PATCH] Added option to preselect an item by providing a number
      5 
      6 ---
      7  config.def.h |  3 +++
      8  dmenu.1      |  5 +++++
      9  dmenu.c      | 15 ++++++++++++++-
     10  3 files changed, 22 insertions(+), 1 deletion(-)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 1edb647..95bee59 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -21,3 +21,6 @@ static unsigned int lines      = 0;
     17   * for example: " /?\"&[]"
     18   */
     19  static const char worddelimiters[] = " ";
     20 +
     21 +/* -n option; preselected item starting from 0 */
     22 +static unsigned int preselected = 0;
     23 diff --git a/dmenu.1 b/dmenu.1
     24 index 323f93c..6e1ee7f 100644
     25 --- a/dmenu.1
     26 +++ b/dmenu.1
     27 @@ -22,6 +22,8 @@ dmenu \- dynamic menu
     28  .IR color ]
     29  .RB [ \-w
     30  .IR windowid ]
     31 +.RB [ \-n
     32 +.IR number ]
     33  .P
     34  .BR dmenu_run " ..."
     35  .SH DESCRIPTION
     36 @@ -80,6 +82,9 @@ prints version information to stdout, then exits.
     37  .TP
     38  .BI \-w " windowid"
     39  embed into windowid.
     40 +.TP
     41 +.BI \-n " number"
     42 +preseslected item starting from 0.
     43  .SH USAGE
     44  dmenu is completely controlled by the keyboard.  Items are selected using the
     45  arrow keys, page up, page down, home, and end.
     46 diff --git a/dmenu.c b/dmenu.c
     47 index 65f25ce..0a02609 100644
     48 --- a/dmenu.c
     49 +++ b/dmenu.c
     50 @@ -551,8 +551,19 @@ static void
     51  run(void)
     52  {
     53  	XEvent ev;
     54 +	int i;
     55  
     56  	while (!XNextEvent(dpy, &ev)) {
     57 +		if (preselected) {
     58 +			for (i = 0; i < preselected; i++) {
     59 +				if (sel && sel->right && (sel = sel->right) == next) {
     60 +					curr = next;
     61 +					calcoffsets();
     62 +				}
     63 +			}
     64 +			drawmenu();
     65 +			preselected = 0;
     66 +		}
     67  		if (XFilterEvent(&ev, win))
     68  			continue;
     69  		switch(ev.type) {
     70 @@ -690,7 +701,7 @@ static void
     71  usage(void)
     72  {
     73  	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     74 -	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
     75 +	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] [-n number]\n", stderr);
     76  	exit(1);
     77  }
     78  
     79 @@ -733,6 +744,8 @@ main(int argc, char *argv[])
     80  			colors[SchemeSel][ColFg] = argv[++i];
     81  		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
     82  			embed = argv[++i];
     83 +		else if (!strcmp(argv[i], "-n"))   /* preselected item */
     84 +			preselected = atoi(argv[++i]);
     85  		else
     86  			usage();
     87  
     88 -- 
     89 2.26.2
     90