sites

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

dmenu-preselect-5.2.diff (1638B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 1edb647..95bee59 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -21,3 +21,6 @@ static unsigned int lines      = 0;
      6   * for example: " /?\"&[]"
      7   */
      8  static const char worddelimiters[] = " ";
      9 +
     10 +/* -n option; preselected item starting from 0 */
     11 +static unsigned int preselected = 0;
     12 diff --git a/dmenu.1 b/dmenu.1
     13 index 323f93c..6e1ee7f 100644
     14 --- a/dmenu.1
     15 +++ b/dmenu.1
     16 @@ -22,6 +22,8 @@ dmenu \- dynamic menu
     17  .IR color ]
     18  .RB [ \-w
     19  .IR windowid ]
     20 +.RB [ \-n
     21 +.IR number ]
     22  .P
     23  .BR dmenu_run " ..."
     24  .SH DESCRIPTION
     25 @@ -80,6 +82,9 @@ prints version information to stdout, then exits.
     26  .TP
     27  .BI \-w " windowid"
     28  embed into windowid.
     29 +.TP
     30 +.BI \-n " number"
     31 +preseslected item starting from 0.
     32  .SH USAGE
     33  dmenu is completely controlled by the keyboard.  Items are selected using the
     34  arrow keys, page up, page down, home, and end.
     35 diff --git a/dmenu.c b/dmenu.c
     36 index 27b7a30..e2e79b3 100644
     37 --- a/dmenu.c
     38 +++ b/dmenu.c
     39 @@ -679,6 +679,12 @@ setup(void)
     40  	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
     41  	inputw = mw / 3; /* input width: ~33% of monitor width */
     42  	match();
     43 +	for (i = 0; i < preselected; i++) {
     44 +		if (sel && sel->right && (sel = sel->right) == next) {
     45 +			curr = next;
     46 +			calcoffsets();
     47 +		}
     48 +	}
     49  
     50  	/* create menu window */
     51  	swa.override_redirect = True;
     52 @@ -757,6 +763,8 @@ main(int argc, char *argv[])
     53  			colors[SchemeSel][ColFg] = argv[++i];
     54  		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
     55  			embed = argv[++i];
     56 +		else if (!strcmp(argv[i], "-n"))   /* preselected item */
     57 +			preselected = atoi(argv[++i]);
     58  		else
     59  			usage();
     60