diff options
author | arg@mig29 <unknown> | 2006-12-13 14:14:41 +0100 |
---|---|---|
committer | arg@mig29 <unknown> | 2006-12-13 14:14:41 +0100 |
commit | 65912f2a96d32600a07b963e9149f70ca22e73bb (patch) | |
tree | 85a475cc19643e958549403874bbcfd40688f034 | |
parent | 4bd34662153f0b2cabac485d01ac2e1300c254c1 (diff) |
added prompt option (-p 'prompt text'), documented in man page as well
-rw-r--r-- | dmenu.1 | 4 | ||||
-rw-r--r-- | main.c | 22 |
2 files changed, 23 insertions, 3 deletions
@@ -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> |
34 | defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). | 35 | defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). |
35 | .TP | 36 | .TP |
37 | .B \-p <prompt> | ||
38 | defines a prompt being displayed before input area. | ||
39 | .TP | ||
36 | .B \-t <seconds> | 40 | .B \-t <seconds> |
37 | defines the seconds to wait for standard input, before exiting (default is 3). | 41 | defines the seconds to wait for standard input, before exiting (default is 3). |
38 | .TP | 42 | .TP |
@@ -25,10 +25,12 @@ struct Item { | |||
25 | /* static */ | 25 | /* static */ |
26 | 26 | ||
27 | static char text[4096]; | 27 | static char text[4096]; |
28 | static char *prompt = NULL; | ||
28 | static int mx, my, mw, mh; | 29 | static int mx, my, mw, mh; |
29 | static int ret = 0; | 30 | static int ret = 0; |
30 | static int nitem = 0; | 31 | static int nitem = 0; |
31 | static unsigned int cmdw = 0; | 32 | static unsigned int cmdw = 0; |
33 | static unsigned int promptw = 0; | ||
32 | static Bool running = True; | 34 | static Bool running = True; |
33 | static Item *allitems = NULL; /* first of all items */ | 35 | static Item *allitems = NULL; /* first of all items */ |
34 | static Item *item = NULL; /* first of pattern matching items */ | 36 | static 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); |