aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 19 insertions, 3 deletions
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);