aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarg@mig29 <unknown>2006-12-13 14:14:41 +0100
committerarg@mig29 <unknown>2006-12-13 14:14:41 +0100
commit65912f2a96d32600a07b963e9149f70ca22e73bb (patch)
tree85a475cc19643e958549403874bbcfd40688f034
parent4bd34662153f0b2cabac485d01ac2e1300c254c1 (diff)
added prompt option (-p 'prompt text'), documented in man page as well
-rw-r--r--dmenu.14
-rw-r--r--main.c22
2 files changed, 23 insertions, 3 deletions
diff --git a/dmenu.1 b/dmenu.1
index ff0c000..38e485d 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -8,6 +8,7 @@ dmenu \- dynamic menu
8.RB [ \-normfg " <color>"] 8.RB [ \-normfg " <color>"]
9.RB [ \-selbg " <color>"] 9.RB [ \-selbg " <color>"]
10.RB [ \-selfg " <color>"] 10.RB [ \-selfg " <color>"]
11.RB [ \-p " <prompt>"]
11.RB [ \-t " <seconds>"] 12.RB [ \-t " <seconds>"]
12.RB [ \-v ] 13.RB [ \-v ]
13.SH DESCRIPTION 14.SH DESCRIPTION
@@ -33,6 +34,9 @@ defines the selected background color (#RGB, #RRGGBB, and color names are suppor
33.B \-selfg <color> 34.B \-selfg <color>
34defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). 35defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
35.TP 36.TP
37.B \-p <prompt>
38defines a prompt being displayed before input area.
39.TP
36.B \-t <seconds> 40.B \-t <seconds>
37defines the seconds to wait for standard input, before exiting (default is 3). 41defines the seconds to wait for standard input, before exiting (default is 3).
38.TP 42.TP
diff --git a/main.c b/main.c
index 0263948..964fad6 100644
--- a/main.c
+++ b/main.c
@@ -25,10 +25,12 @@ struct Item {
25/* static */ 25/* static */
26 26
27static char text[4096]; 27static char text[4096];
28static char *prompt = NULL;
28static int mx, my, mw, mh; 29static int mx, my, mw, mh;
29static int ret = 0; 30static int ret = 0;
30static int nitem = 0; 31static int nitem = 0;
31static unsigned int cmdw = 0; 32static unsigned int cmdw = 0;
33static unsigned int promptw = 0;
32static Bool running = True; 34static Bool running = True;
33static Item *allitems = NULL; /* first of all items */ 35static Item *allitems = NULL; /* first of all items */
34static Item *item = NULL; /* first of pattern matching items */ 36static Item *item = NULL; /* first of pattern matching items */
@@ -45,7 +47,7 @@ calcoffsets(void) {
45 47
46 if(!curr) 48 if(!curr)
47 return; 49 return;
48 w = cmdw + 2 * SPACE; 50 w = promptw + cmdw + 2 * SPACE;
49 for(next = curr; next; next=next->right) { 51 for(next = curr; next; next=next->right) {
50 tw = textw(next->text); 52 tw = textw(next->text);
51 if(tw > mw / 3) 53 if(tw > mw / 3)
@@ -54,7 +56,7 @@ calcoffsets(void) {
54 if(w > mw) 56 if(w > mw)
55 break; 57 break;
56 } 58 }
57 w = cmdw + 2 * SPACE; 59 w = promptw + cmdw + 2 * SPACE;
58 for(prev = curr; prev && prev->left; prev=prev->left) { 60 for(prev = curr; prev && prev->left; prev=prev->left) {
59 tw = textw(prev->left->text); 61 tw = textw(prev->left->text);
60 if(tw > mw / 3) 62 if(tw > mw / 3)
@@ -74,6 +76,13 @@ drawmenu(void) {
74 dc.w = mw; 76 dc.w = mw;
75 dc.h = mh; 77 dc.h = mh;
76 drawtext(NULL, dc.norm); 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 /* print command */ 86 /* print command */
78 if(cmdw && item) 87 if(cmdw && item)
79 dc.w = cmdw; 88 dc.w = cmdw;
@@ -326,6 +335,9 @@ main(int argc, char *argv[]) {
326 else if(!strncmp(argv[i], "-selfg", 7)) { 335 else if(!strncmp(argv[i], "-selfg", 7)) {
327 if(++i < argc) selfg = argv[i]; 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 else if(!strncmp(argv[i], "-t", 3)) { 341 else if(!strncmp(argv[i], "-t", 3)) {
330 if(++i < argc) timeout.tv_sec = atoi(argv[i]); 342 if(++i < argc) timeout.tv_sec = atoi(argv[i]);
331 } 343 }
@@ -334,7 +346,7 @@ main(int argc, char *argv[]) {
334 exit(EXIT_SUCCESS); 346 exit(EXIT_SUCCESS);
335 } 347 }
336 else 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 setlocale(LC_CTYPE, ""); 350 setlocale(LC_CTYPE, "");
339 dpy = XOpenDisplay(0); 351 dpy = XOpenDisplay(0);
340 if(!dpy) 352 if(!dpy)
@@ -380,6 +392,10 @@ main(int argc, char *argv[]) {
380 cmdw = textw(maxname); 392 cmdw = textw(maxname);
381 if(cmdw > mw / 3) 393 if(cmdw > mw / 3)
382 cmdw = mw / 3; 394 cmdw = mw / 3;
395 if(prompt)
396 promptw = textw(prompt);
397 if(promptw > mw / 5)
398 promptw = mw / 5;
383 text[0] = 0; 399 text[0] = 0;
384 match(text); 400 match(text);
385 XMapRaised(dpy, win); 401 XMapRaised(dpy, win);