added prompt option (-p 'prompt text'), documented in man page as well 65912f2a
arg@mig29 · 2006-12-13 14:14 2 file(s) · +23 −3
dmenu.1 +4 −0
8 8
.RB [ \-normfg " <color>"]
9 9
.RB [ \-selbg " <color>"]
10 10
.RB [ \-selfg " <color>"]
11 +
.RB [ \-p " <prompt>"]
11 12
.RB [ \-t " <seconds>"]
12 13
.RB [ \-v ]
13 14
.SH DESCRIPTION
32 33
.TP
33 34
.B \-selfg <color>
34 35
defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
36 +
.TP
37 +
.B \-p <prompt>
38 +
defines a prompt being displayed before input area.
35 39
.TP
36 40
.B \-t <seconds>
37 41
defines the seconds to wait for standard input, before exiting (default is 3).
main.c +19 −3
25 25
/* static */
26 26
27 27
static char text[4096];
28 +
static char *prompt = NULL;
28 29
static int mx, my, mw, mh;
29 30
static int ret = 0;
30 31
static int nitem = 0;
31 32
static unsigned int cmdw = 0;
33 +
static unsigned int promptw = 0;
32 34
static Bool running = True;
33 35
static Item *allitems = NULL;	/* first of all items */
34 36
static Item *item = NULL;	/* first of pattern matching items */
45 47
46 48
	if(!curr)
47 49
		return;
48 -
	w = cmdw + 2 * SPACE;
50 +
	w = promptw + cmdw + 2 * SPACE;
49 51
	for(next = curr; next; next=next->right) {
50 52
		tw = textw(next->text);
51 53
		if(tw > mw / 3)
54 56
		if(w > mw)
55 57
			break;
56 58
	}
57 -
	w = cmdw + 2 * SPACE;
59 +
	w = promptw + cmdw + 2 * SPACE;
58 60
	for(prev = curr; prev && prev->left; prev=prev->left) {
59 61
		tw = textw(prev->left->text);
60 62
		if(tw > mw / 3)
74 76
	dc.w = mw;
75 77
	dc.h = mh;
76 78
	drawtext(NULL, dc.norm);
79 +
	/* print prompt? */
80 +
	if(promptw) {
81 +
		dc.w = promptw;
82 +
		drawtext(prompt, dc.sel);
83 +
	}
84 +
	dc.x += promptw;
85 +
	dc.w = mw - promptw;
77 86
	/* print command */
78 87
	if(cmdw && item)
79 88
		dc.w = cmdw;
326 335
		else if(!strncmp(argv[i], "-selfg", 7)) {
327 336
			if(++i < argc) selfg = argv[i];
328 337
		}
338 +
		else if(!strncmp(argv[i], "-p", 3)) {
339 +
			if(++i < argc) prompt = argv[i];
340 +
		}
329 341
		else if(!strncmp(argv[i], "-t", 3)) {
330 342
			if(++i < argc) timeout.tv_sec = atoi(argv[i]);
331 343
		}
334 346
			exit(EXIT_SUCCESS);
335 347
		}
336 348
		else
337 -
			eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-t <seconds>] [-v]\n", stdout);
349 +
			eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-p <prompt>] [-t <seconds>] [-v]\n", stdout);
338 350
	setlocale(LC_CTYPE, "");
339 351
	dpy = XOpenDisplay(0);
340 352
	if(!dpy)
380 392
		cmdw = textw(maxname);
381 393
	if(cmdw > mw / 3)
382 394
		cmdw = mw / 3;
395 +
	if(prompt)
396 +
		promptw = textw(prompt);
397 +
	if(promptw > mw / 5)
398 +
		promptw = mw / 5;
383 399
	text[0] = 0;
384 400
	match(text);
385 401
	XMapRaised(dpy, win);