added prompt option (-p 'prompt text'), documented in man page as well

master
arg@mig29 18 years ago
parent 4bd3466215
commit 65912f2a96
  1. 4
      dmenu.1
  2. 22
      main.c

@ -8,6 +8,7 @@ dmenu \- dynamic menu
.RB [ \-normfg " <color>"] .RB [ \-normfg " <color>"]
.RB [ \-selbg " <color>"] .RB [ \-selbg " <color>"]
.RB [ \-selfg " <color>"] .RB [ \-selfg " <color>"]
.RB [ \-p " <prompt>"]
.RB [ \-t " <seconds>"] .RB [ \-t " <seconds>"]
.RB [ \-v ] .RB [ \-v ]
.SH DESCRIPTION .SH DESCRIPTION
@ -33,6 +34,9 @@ defines the selected background color (#RGB, #RRGGBB, and color names are suppor
.B \-selfg <color> .B \-selfg <color>
defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
.TP .TP
.B \-p <prompt>
defines a prompt being displayed before input area.
.TP
.B \-t <seconds> .B \-t <seconds>
defines the seconds to wait for standard input, before exiting (default is 3). defines the seconds to wait for standard input, before exiting (default is 3).
.TP .TP

@ -25,10 +25,12 @@ struct Item {
/* static */ /* static */
static char text[4096]; static char text[4096];
static char *prompt = NULL;
static int mx, my, mw, mh; static int mx, my, mw, mh;
static int ret = 0; static int ret = 0;
static int nitem = 0; static int nitem = 0;
static unsigned int cmdw = 0; static unsigned int cmdw = 0;
static unsigned int promptw = 0;
static Bool running = True; static Bool running = True;
static Item *allitems = NULL; /* first of all items */ static Item *allitems = NULL; /* first of all items */
static Item *item = NULL; /* first of pattern matching items */ static Item *item = NULL; /* first of pattern matching items */
@ -45,7 +47,7 @@ calcoffsets(void) {
if(!curr) if(!curr)
return; return;
w = cmdw + 2 * SPACE; w = promptw + cmdw + 2 * SPACE;
for(next = curr; next; next=next->right) { for(next = curr; next; next=next->right) {
tw = textw(next->text); tw = textw(next->text);
if(tw > mw / 3) if(tw > mw / 3)
@ -54,7 +56,7 @@ calcoffsets(void) {
if(w > mw) if(w > mw)
break; break;
} }
w = cmdw + 2 * SPACE; w = promptw + cmdw + 2 * SPACE;
for(prev = curr; prev && prev->left; prev=prev->left) { for(prev = curr; prev && prev->left; prev=prev->left) {
tw = textw(prev->left->text); tw = textw(prev->left->text);
if(tw > mw / 3) if(tw > mw / 3)
@ -74,6 +76,13 @@ drawmenu(void) {
dc.w = mw; dc.w = mw;
dc.h = mh; dc.h = mh;
drawtext(NULL, dc.norm); drawtext(NULL, dc.norm);
/* print prompt? */
if(promptw) {
dc.w = promptw;
drawtext(prompt, dc.sel);
}
dc.x += promptw;
dc.w = mw - promptw;
/* print command */ /* print command */
if(cmdw && item) if(cmdw && item)
dc.w = cmdw; dc.w = cmdw;
@ -326,6 +335,9 @@ main(int argc, char *argv[]) {
else if(!strncmp(argv[i], "-selfg", 7)) { else if(!strncmp(argv[i], "-selfg", 7)) {
if(++i < argc) selfg = argv[i]; if(++i < argc) selfg = argv[i];
} }
else if(!strncmp(argv[i], "-p", 3)) {
if(++i < argc) prompt = argv[i];
}
else if(!strncmp(argv[i], "-t", 3)) { else if(!strncmp(argv[i], "-t", 3)) {
if(++i < argc) timeout.tv_sec = atoi(argv[i]); if(++i < argc) timeout.tv_sec = atoi(argv[i]);
} }
@ -334,7 +346,7 @@ main(int argc, char *argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
else else
eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-t <seconds>] [-v]\n", stdout); eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-p <prompt>] [-t <seconds>] [-v]\n", stdout);
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
dpy = XOpenDisplay(0); dpy = XOpenDisplay(0);
if(!dpy) if(!dpy)
@ -380,6 +392,10 @@ main(int argc, char *argv[]) {
cmdw = textw(maxname); cmdw = textw(maxname);
if(cmdw > mw / 3) if(cmdw > mw / 3)
cmdw = mw / 3; cmdw = mw / 3;
if(prompt)
promptw = textw(prompt);
if(promptw > mw / 5)
promptw = mw / 5;
text[0] = 0; text[0] = 0;
match(text); match(text);
XMapRaised(dpy, win); XMapRaised(dpy, win);

Loading…
Cancel
Save