removed -t title crap from dmenu
ee03052e
2 file(s) · +12 −57
| 4 | 4 | .SH SYNOPSIS |
|
| 5 | 5 | .B dmenu |
|
| 6 | 6 | .RB [ \-v ] |
|
| 7 | - | .RB [ \-t |
|
| 8 | - | .IR title ] |
|
| 9 | 7 | .SH DESCRIPTION |
|
| 10 | 8 | .SS Overview |
|
| 11 | 9 | .B dmenu |
|
| 17 | 15 | .TP |
|
| 18 | 16 | .B \-v |
|
| 19 | 17 | prints version information to stdout, then exits. |
|
| 20 | - | .TP |
|
| 21 | - | .BI \-t " title" |
|
| 22 | - | displays |
|
| 23 | - | .I title |
|
| 24 | - | above the menu. |
|
| 25 | 18 | .SS Usage |
|
| 26 | 19 | .B dmenu |
|
| 27 | 20 | reads a list of newline-separated items from stdin and creates a menu. |
|
| 24 | 24 | ||
| 25 | 25 | /* static */ |
|
| 26 | 26 | ||
| 27 | - | static char *title, text[4096]; |
|
| 27 | + | static char text[4096]; |
|
| 28 | 28 | static int mx, my, mw, mh; |
|
| 29 | 29 | static int ret = 0; |
|
| 30 | 30 | static int nitem = 0; |
|
| 31 | 31 | static unsigned int cmdw = 0; |
|
| 32 | - | static unsigned int tw = 0; |
|
| 33 | - | static unsigned int cw = 0; |
|
| 34 | 32 | static Bool done = False; |
|
| 35 | 33 | static Item *allitems = NULL; /* first of all items */ |
|
| 36 | 34 | static Item *item = NULL; /* first of pattern matching items */ |
|
| 82 | 80 | drawtext(NULL, False, False); |
|
| 83 | 81 | ||
| 84 | 82 | /* print command */ |
|
| 85 | - | if(!title || text[0]) { |
|
| 86 | - | cmdw = cw; |
|
| 87 | - | if(cmdw && item) |
|
| 88 | - | dc.w = cmdw; |
|
| 89 | - | drawtext(text, False, False); |
|
| 90 | - | } |
|
| 91 | - | else { |
|
| 92 | - | cmdw = tw; |
|
| 83 | + | if(cmdw && item) |
|
| 93 | 84 | dc.w = cmdw; |
|
| 94 | - | drawtext(title, False, False); |
|
| 95 | - | } |
|
| 96 | - | dc.x += dc.w; |
|
| 85 | + | drawtext(text[0] ? text : NULL, False, False); |
|
| 86 | + | dc.x += cmdw; |
|
| 97 | 87 | ||
| 98 | 88 | if(curr) { |
|
| 99 | 89 | dc.w = SPACE; |
|
| 126 | 116 | ||
| 127 | 117 | if(!pattern) |
|
| 128 | 118 | return; |
|
| 129 | - | ||
| 130 | - | if(!title || *pattern) |
|
| 131 | - | cmdw = cw; |
|
| 132 | - | else |
|
| 133 | - | cmdw = tw; |
|
| 134 | 119 | ||
| 135 | 120 | plen = strlen(pattern); |
|
| 136 | 121 | item = j = NULL; |
|
| 308 | 293 | main(int argc, char *argv[]) |
|
| 309 | 294 | { |
|
| 310 | 295 | char *maxname; |
|
| 311 | - | int i; |
|
| 312 | 296 | XEvent ev; |
|
| 313 | 297 | XSetWindowAttributes wa; |
|
| 314 | 298 | ||
| 315 | - | /* command line args */ |
|
| 316 | - | for(i = 1; i < argc; i++) { |
|
| 317 | - | if (argv[i][0] == '-') |
|
| 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"); |
|
| 299 | + | if(argc == 2 && !strncmp("-v", argv[1], 3)) { |
|
| 300 | + | fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
|
| 301 | + | exit(EXIT_SUCCESS); |
|
| 334 | 302 | } |
|
| 303 | + | else if(argc != 1) |
|
| 304 | + | eprint("usage: dmenu [-v]\n"); |
|
| 335 | 305 | ||
| 336 | 306 | dpy = XOpenDisplay(0); |
|
| 337 | 307 | if(!dpy) |
|
| 371 | 341 | dc.gc = XCreateGC(dpy, root, 0, 0); |
|
| 372 | 342 | ||
| 373 | 343 | if(maxname) |
|
| 374 | - | cw = textw(maxname); |
|
| 375 | - | if(cw > mw / 3) |
|
| 376 | - | cw = 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; |
|
| 344 | + | cmdw = textw(maxname); |
|
| 345 | + | if(cmdw > mw / 3) |
|
| 346 | + | cmdw = mw / 3; |
|
| 385 | 347 | ||
| 386 | 348 | text[0] = 0; |
|
| 387 | 349 | input(text); |
|