aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c62
1 files changed, 12 insertions, 50 deletions
diff --git a/main.c b/main.c
index 32b08b9..f151819 100644
--- a/main.c
+++ b/main.c
@@ -24,13 +24,11 @@ struct Item {
24 24
25/* static */ 25/* static */
26 26
27static char *title, text[4096]; 27static char text[4096];
28static int mx, my, mw, mh; 28static int mx, my, mw, mh;
29static int ret = 0; 29static int ret = 0;
30static int nitem = 0; 30static int nitem = 0;
31static unsigned int cmdw = 0; 31static unsigned int cmdw = 0;
32static unsigned int tw = 0;
33static unsigned int cw = 0;
34static Bool done = False; 32static Bool done = False;
35static Item *allitems = NULL; /* first of all items */ 33static Item *allitems = NULL; /* first of all items */
36static Item *item = NULL; /* first of pattern matching items */ 34static Item *item = NULL; /* first of pattern matching items */
@@ -82,18 +80,10 @@ drawmenu()
82 drawtext(NULL, False, False); 80 drawtext(NULL, False, False);
83 81
84 /* print command */ 82 /* print command */
85 if(!title || text[0]) { 83 if(cmdw && item)
86 cmdw = cw;
87 if(cmdw && item)
88 dc.w = cmdw;
89 drawtext(text, False, False);
90 }
91 else {
92 cmdw = tw;
93 dc.w = cmdw; 84 dc.w = cmdw;
94 drawtext(title, False, False); 85 drawtext(text[0] ? text : NULL, False, False);
95 } 86 dc.x += cmdw;
96 dc.x += dc.w;
97 87
98 if(curr) { 88 if(curr) {
99 dc.w = SPACE; 89 dc.w = SPACE;
@@ -127,11 +117,6 @@ input(char *pattern)
127 if(!pattern) 117 if(!pattern)
128 return; 118 return;
129 119
130 if(!title || *pattern)
131 cmdw = cw;
132 else
133 cmdw = tw;
134
135 plen = strlen(pattern); 120 plen = strlen(pattern);
136 item = j = NULL; 121 item = j = NULL;
137 nitem = 0; 122 nitem = 0;
@@ -308,30 +293,15 @@ int
308main(int argc, char *argv[]) 293main(int argc, char *argv[])
309{ 294{
310 char *maxname; 295 char *maxname;
311 int i;
312 XEvent ev; 296 XEvent ev;
313 XSetWindowAttributes wa; 297 XSetWindowAttributes wa;
314 298
315 /* command line args */ 299 if(argc == 2 && !strncmp("-v", argv[1], 3)) {
316 for(i = 1; i < argc; i++) { 300 fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
317 if (argv[i][0] == '-') 301 exit(EXIT_SUCCESS);
318 switch (argv[i][1]) {
319 case 'v':
320 fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
321 exit(EXIT_SUCCESS);
322 break;
323 case 't':
324 if(++i < argc) {
325 title = argv[i];
326 break;
327 }
328 default:
329 eprint("usage: dmenu [-v] [-t <title>]\n");
330 break;
331 }
332 else
333 eprint("usage: dmenu [-v] [-t <title>]\n");
334 } 302 }
303 else if(argc != 1)
304 eprint("usage: dmenu [-v]\n");
335 305
336 dpy = XOpenDisplay(0); 306 dpy = XOpenDisplay(0);
337 if(!dpy) 307 if(!dpy)
@@ -371,17 +341,9 @@ main(int argc, char *argv[])
371 dc.gc = XCreateGC(dpy, root, 0, 0); 341 dc.gc = XCreateGC(dpy, root, 0, 0);
372 342
373 if(maxname) 343 if(maxname)
374 cw = textw(maxname); 344 cmdw = textw(maxname);
375 if(cw > mw / 3) 345 if(cmdw > mw / 3)
376 cw = mw / 3; 346 cmdw = mw / 3;
377
378 if(title) {
379 tw = textw(title);
380 if(tw > mw / 3)
381 tw = mw / 3;
382 }
383
384 cmdw = title ? tw : cw;
385 347
386 text[0] = 0; 348 text[0] = 0;
387 input(text); 349 input(text);