diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -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); |