~lh2/dmenu

3b75704654dbd59a953c5b814cbc7ce69b98944b — Mathieu Moneyron 4 years ago ecd86f3 master
Added option to preselect an item by providing a number
3 files changed, 22 insertions(+), 1 deletions(-)

M config.def.h
M dmenu.1
M dmenu.c
M config.def.h => config.def.h +3 -0
@@ 21,3 21,6 @@ static unsigned int lines      = 0;
 * for example: " /?\"&[]"
 */
static const char worddelimiters[] = " ";

/* -n option; preselected item starting from 0 */
static unsigned int preselected = 0;

M dmenu.1 => dmenu.1 +5 -0
@@ 22,6 22,8 @@ dmenu \- dynamic menu
.IR color ]
.RB [ \-w
.IR windowid ]
.RB [ \-n
.IR number ]
.P
.BR dmenu_run " ..."
.SH DESCRIPTION


@@ 80,6 82,9 @@ prints version information to stdout, then exits.
.TP
.BI \-w " windowid"
embed into windowid.
.TP
.BI \-n " number"
preseslected item starting from 0.
.SH USAGE
dmenu is completely controlled by the keyboard.  Items are selected using the
arrow keys, page up, page down, home, and end.

M dmenu.c => dmenu.c +14 -1
@@ 556,8 556,19 @@ static void
run(void)
{
	XEvent ev;
	int i;

	while (!XNextEvent(dpy, &ev)) {
		if (preselected) {
			for (i = 0; i < preselected; i++) {
				if (sel && sel->right && (sel = sel->right) == next) {
					curr = next;
					calcoffsets();
				}
			}
			drawmenu();
			preselected = 0;
		}
		if (XFilterEvent(&ev, win))
			continue;
		switch(ev.type) {


@@ 700,7 711,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 number]\n", stderr);
	exit(1);
}



@@ 778,6 789,8 @@ main(int argc, char *argv[])
			colortemp[3] = argv[++i];
		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
			embed = argv[++i];
		else if (!strcmp(argv[i], "-n"))   /* preselected item */
			preselected = atoi(argv[++i]);
		else
			usage();