My dmenu build
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

687 lines
17 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #include <ctype.h>
  3. #include <locale.h>
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <strings.h>
  9. #include <unistd.h>
  10. #include <X11/Xlib.h>
  11. #include <X11/Xatom.h>
  12. #include <X11/Xutil.h>
  13. #ifdef XINERAMA
  14. #include <X11/extensions/Xinerama.h>
  15. #endif
  16. #include <X11/Xft/Xft.h>
  17. #include "drw.h"
  18. #include "util.h"
  19. /* macros */
  20. #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
  21. * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
  22. #define LENGTH(X) (sizeof X / sizeof X[0])
  23. #define TEXTNW(X,N) (drw_font_getexts_width(drw->fonts[0], (X), (N)))
  24. #define TEXTW(X) (drw_text(drw, 0, 0, 0, 0, (X), 0) + drw->fonts[0]->h)
  25. /* enums */
  26. enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
  27. typedef struct Item Item;
  28. struct Item {
  29. char *text;
  30. Item *left, *right;
  31. bool out;
  32. };
  33. static void appenditem(Item *item, Item **list, Item **last);
  34. static void calcoffsets(void);
  35. static char *cistrstr(const char *s, const char *sub);
  36. static void cleanup(void);
  37. static void drawmenu(void);
  38. static void grabkeyboard(void);
  39. static void insert(const char *str, ssize_t n);
  40. static void keypress(XKeyEvent *ev);
  41. static void match(void);
  42. static size_t nextrune(int inc);
  43. static void paste(void);
  44. static void readstdin(void);
  45. static void run(void);
  46. static void setup(void);
  47. static void usage(void);
  48. static char text[BUFSIZ] = "";
  49. static int bh, mw, mh;
  50. static int inputw, promptw;
  51. static size_t cursor = 0;
  52. static Atom clip, utf8;
  53. static Item *items = NULL;
  54. static Item *matches, *matchend;
  55. static Item *prev, *curr, *next, *sel;
  56. static Window win;
  57. static XIC xic;
  58. static int mon = -1;
  59. static ClrScheme scheme[SchemeLast];
  60. static Display *dpy;
  61. static int screen;
  62. static Window root;
  63. static Drw *drw;
  64. static int sw, sh; /* X display screen geometry width, height */
  65. #include "config.h"
  66. static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
  67. static char *(*fstrstr)(const char *, const char *) = strstr;
  68. int
  69. main(int argc, char *argv[]) {
  70. bool fast = false;
  71. int i;
  72. for(i = 1; i < argc; i++)
  73. /* these options take no arguments */
  74. if(!strcmp(argv[i], "-v")) { /* prints version information */
  75. puts("dmenu-"VERSION", © 2006-2015 dmenu engineers, see LICENSE for details");
  76. exit(0);
  77. }
  78. else if(!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */
  79. topbar = false;
  80. else if(!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
  81. fast = true;
  82. else if(!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
  83. fstrncmp = strncasecmp;
  84. fstrstr = cistrstr;
  85. }
  86. else if(i+1 == argc)
  87. usage();
  88. /* these options take one argument */
  89. else if(!strcmp(argv[i], "-l")) /* number of lines in vertical list */
  90. lines = atoi(argv[++i]);
  91. else if(!strcmp(argv[i], "-m"))
  92. mon = atoi(argv[++i]);
  93. else if(!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
  94. prompt = argv[++i];
  95. else if(!strcmp(argv[i], "-fn")) /* font or font set */
  96. fonts[0] = argv[++i];
  97. else if(!strcmp(argv[i], "-nb")) /* normal background color */
  98. normbgcolor = argv[++i];
  99. else if(!strcmp(argv[i], "-nf")) /* normal foreground color */
  100. normfgcolor = argv[++i];
  101. else if(!strcmp(argv[i], "-sb")) /* selected background color */
  102. selbgcolor = argv[++i];
  103. else if(!strcmp(argv[i], "-sf")) /* selected foreground color */
  104. selfgcolor = argv[++i];
  105. else
  106. usage();
  107. if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
  108. fputs("warning: no locale support\n", stderr);
  109. if(!(dpy = XOpenDisplay(NULL)))
  110. die("dmenu: cannot open display\n");
  111. screen = DefaultScreen(dpy);
  112. root = RootWindow(dpy, screen);
  113. sw = DisplayWidth(dpy, screen);
  114. sh = DisplayHeight(dpy, screen);
  115. drw = drw_create(dpy, screen, root, sw, sh);
  116. drw_load_fonts(drw, fonts, LENGTH(fonts));
  117. if(!drw->fontcount)
  118. die("No fonts could be loaded.\n");
  119. drw_setscheme(drw, &scheme[SchemeNorm]);
  120. if(fast) {
  121. grabkeyboard();
  122. readstdin();
  123. }
  124. else {
  125. readstdin();
  126. grabkeyboard();
  127. }
  128. setup();
  129. run();
  130. return 1; /* unreachable */
  131. }
  132. void
  133. appenditem(Item *item, Item **list, Item **last) {
  134. if(*last)
  135. (*last)->right = item;
  136. else
  137. *list = item;
  138. item->left = *last;
  139. item->right = NULL;
  140. *last = item;
  141. }
  142. void
  143. calcoffsets(void) {
  144. int i, n;
  145. if(lines > 0)
  146. n = lines * bh;
  147. else
  148. n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
  149. /* calculate which items will begin the next page and previous page */
  150. for(i = 0, next = curr; next; next = next->right)
  151. if((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
  152. break;
  153. for(i = 0, prev = curr; prev && prev->left; prev = prev->left)
  154. if((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n)
  155. break;
  156. }
  157. void
  158. cleanup(void) {
  159. XUngrabKey(dpy, AnyKey, AnyModifier, root);
  160. drw_clr_free(scheme[SchemeNorm].bg);
  161. drw_clr_free(scheme[SchemeNorm].fg);
  162. drw_clr_free(scheme[SchemeSel].fg);
  163. drw_clr_free(scheme[SchemeSel].bg);
  164. drw_clr_free(scheme[SchemeOut].fg);
  165. drw_clr_free(scheme[SchemeOut].bg);
  166. drw_free(drw);
  167. XSync(dpy, False);
  168. XCloseDisplay(dpy);
  169. }
  170. char *
  171. cistrstr(const char *s, const char *sub) {
  172. size_t len;
  173. for(len = strlen(sub); *s; s++)
  174. if(!strncasecmp(s, sub, len))
  175. return (char *)s;
  176. return NULL;
  177. }
  178. void
  179. drawmenu(void) {
  180. int curpos;
  181. Item *item;
  182. int x = 0, y = 0, h = bh, w;
  183. drw_setscheme(drw, &scheme[SchemeNorm]);
  184. drw_rect(drw, 0, 0, mw, mh, 1, 1, 1);
  185. if(prompt && *prompt) {
  186. drw_setscheme(drw, &scheme[SchemeSel]);
  187. drw_text(drw, x, 0, promptw, bh, prompt, 0);
  188. x += promptw;
  189. }
  190. /* draw input field */
  191. w = (lines > 0 || !matches) ? mw - x : inputw;
  192. drw_setscheme(drw, &scheme[SchemeNorm]);
  193. drw_text(drw, x, 0, w, bh, text, 0);
  194. if((curpos = TEXTNW(text, cursor) + bh/2 - 2) < w) {
  195. drw_setscheme(drw, &scheme[SchemeNorm]);
  196. drw_rect(drw, x + curpos + 2, 2, 1, bh - 4, 1, 1, 0);
  197. }
  198. if(lines > 0) {
  199. /* draw vertical list */
  200. w = mw - x;
  201. for(item = curr; item != next; item = item->right) {
  202. y += h;
  203. if(item == sel)
  204. drw_setscheme(drw, &scheme[SchemeSel]);
  205. else if(item->out)
  206. drw_setscheme(drw, &scheme[SchemeOut]);
  207. else
  208. drw_setscheme(drw, &scheme[SchemeNorm]);
  209. drw_text(drw, x, y, w, bh, item->text, 0);
  210. }
  211. }
  212. else if(matches) {
  213. /* draw horizontal list */
  214. x += inputw;
  215. w = TEXTW("<");
  216. if(curr->left) {
  217. drw_setscheme(drw, &scheme[SchemeNorm]);
  218. drw_text(drw, x, 0, w, bh, "<", 0);
  219. }
  220. for(item = curr; item != next; item = item->right) {
  221. x += w;
  222. w = MIN(TEXTW(item->text), mw - x - TEXTW(">"));
  223. if(item == sel)
  224. drw_setscheme(drw, &scheme[SchemeSel]);
  225. else if(item->out)
  226. drw_setscheme(drw, &scheme[SchemeOut]);
  227. else
  228. drw_setscheme(drw, &scheme[SchemeNorm]);
  229. drw_text(drw, x, 0, w, bh, item->text, 0);
  230. }
  231. w = TEXTW(">");
  232. x = mw - w;
  233. if(next) {
  234. drw_setscheme(drw, &scheme[SchemeNorm]);
  235. drw_text(drw, x, 0, w, bh, ">", 0);
  236. }
  237. }
  238. drw_map(drw, win, 0, 0, mw, mh);
  239. }
  240. void
  241. grabkeyboard(void) {
  242. int i;
  243. /* try to grab keyboard, we may have to wait for another process to ungrab */
  244. for(i = 0; i < 1000; i++) {
  245. if(XGrabKeyboard(dpy, DefaultRootWindow(dpy), True,
  246. GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
  247. return;
  248. usleep(1000);
  249. }
  250. die("cannot grab keyboard\n");
  251. }
  252. void
  253. insert(const char *str, ssize_t n) {
  254. if(strlen(text) + n > sizeof text - 1)
  255. return;
  256. /* move existing text out of the way, insert new text, and update cursor */
  257. memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0));
  258. if(n > 0)
  259. memcpy(&text[cursor], str, n);
  260. cursor += n;
  261. match();
  262. }
  263. void
  264. keypress(XKeyEvent *ev) {
  265. char buf[32];
  266. int len;
  267. KeySym ksym = NoSymbol;
  268. Status status;
  269. len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
  270. if(status == XBufferOverflow)
  271. return;
  272. if(ev->state & ControlMask)
  273. switch(ksym) {
  274. case XK_a: ksym = XK_Home; break;
  275. case XK_b: ksym = XK_Left; break;
  276. case XK_c: ksym = XK_Escape; break;
  277. case XK_d: ksym = XK_Delete; break;
  278. case XK_e: ksym = XK_End; break;
  279. case XK_f: ksym = XK_Right; break;
  280. case XK_g: ksym = XK_Escape; break;
  281. case XK_h: ksym = XK_BackSpace; break;
  282. case XK_i: ksym = XK_Tab; break;
  283. case XK_j: /* fallthrough */
  284. case XK_J: /* fallthrough */
  285. case XK_m: /* fallthrough */
  286. case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break;
  287. case XK_n: ksym = XK_Down; break;
  288. case XK_p: ksym = XK_Up; break;
  289. case XK_k: /* delete right */
  290. text[cursor] = '\0';
  291. match();
  292. break;
  293. case XK_u: /* delete left */
  294. insert(NULL, 0 - cursor);
  295. break;
  296. case XK_w: /* delete word */
  297. while(cursor > 0 && text[nextrune(-1)] == ' ')
  298. insert(NULL, nextrune(-1) - cursor);
  299. while(cursor > 0 && text[nextrune(-1)] != ' ')
  300. insert(NULL, nextrune(-1) - cursor);
  301. break;
  302. case XK_y: /* paste selection */
  303. XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
  304. utf8, utf8, win, CurrentTime);
  305. return;
  306. case XK_Return:
  307. case XK_KP_Enter:
  308. break;
  309. case XK_bracketleft:
  310. cleanup();
  311. exit(1);
  312. default:
  313. return;
  314. }
  315. else if(ev->state & Mod1Mask)
  316. switch(ksym) {
  317. case XK_g: ksym = XK_Home; break;
  318. case XK_G: ksym = XK_End; break;
  319. case XK_h: ksym = XK_Up; break;
  320. case XK_j: ksym = XK_Next; break;
  321. case XK_k: ksym = XK_Prior; break;
  322. case XK_l: ksym = XK_Down; break;
  323. default:
  324. return;
  325. }
  326. switch(ksym) {
  327. default:
  328. if(!iscntrl(*buf))
  329. insert(buf, len);
  330. break;
  331. case XK_Delete:
  332. if(text[cursor] == '\0')
  333. return;
  334. cursor = nextrune(+1);
  335. /* fallthrough */
  336. case XK_BackSpace:
  337. if(cursor == 0)
  338. return;
  339. insert(NULL, nextrune(-1) - cursor);
  340. break;
  341. case XK_End:
  342. if(text[cursor] != '\0') {
  343. cursor = strlen(text);
  344. break;
  345. }
  346. if(next) {
  347. /* jump to end of list and position items in reverse */
  348. curr = matchend;
  349. calcoffsets();
  350. curr = prev;
  351. calcoffsets();
  352. while(next && (curr = curr->right))
  353. calcoffsets();
  354. }
  355. sel = matchend;
  356. break;
  357. case XK_Escape:
  358. cleanup();
  359. exit(1);
  360. case XK_Home:
  361. if(sel == matches) {
  362. cursor = 0;
  363. break;
  364. }
  365. sel = curr = matches;
  366. calcoffsets();
  367. break;
  368. case XK_Left:
  369. if(cursor > 0 && (!sel || !sel->left || lines > 0)) {
  370. cursor = nextrune(-1);
  371. break;
  372. }
  373. if(lines > 0)
  374. return;
  375. /* fallthrough */
  376. case XK_Up:
  377. if(sel && sel->left && (sel = sel->left)->right == curr) {
  378. curr = prev;
  379. calcoffsets();
  380. }
  381. break;
  382. case XK_Next:
  383. if(!next)
  384. return;
  385. sel = curr = next;
  386. calcoffsets();
  387. break;
  388. case XK_Prior:
  389. if(!prev)
  390. return;
  391. sel = curr = prev;
  392. calcoffsets();
  393. break;
  394. case XK_Return:
  395. case XK_KP_Enter:
  396. puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
  397. if(!(ev->state & ControlMask)) {
  398. cleanup();
  399. exit(0);
  400. }
  401. if(sel)
  402. sel->out = true;
  403. break;
  404. case XK_Right:
  405. if(text[cursor] != '\0') {
  406. cursor = nextrune(+1);
  407. break;
  408. }
  409. if(lines > 0)
  410. return;
  411. /* fallthrough */
  412. case XK_Down:
  413. if(sel && sel->right && (sel = sel->right) == next) {
  414. curr = next;
  415. calcoffsets();
  416. }
  417. break;
  418. case XK_Tab:
  419. if(!sel)
  420. return;
  421. strncpy(text, sel->text, sizeof text - 1);
  422. text[sizeof text - 1] = '\0';
  423. cursor = strlen(text);
  424. match();
  425. break;
  426. }
  427. drawmenu();
  428. }
  429. void
  430. match(void) {
  431. static char **tokv = NULL;
  432. static int tokn = 0;
  433. char buf[sizeof text], *s;
  434. int i, tokc = 0;
  435. size_t len;
  436. Item *item, *lprefix, *lsubstr, *prefixend, *substrend;
  437. strcpy(buf, text);
  438. /* separate input text into tokens to be matched individually */
  439. for(s = strtok(buf, " "); s; tokv[tokc-1] = s, s = strtok(NULL, " "))
  440. if(++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv)))
  441. die("cannot realloc %u bytes\n", tokn * sizeof *tokv);
  442. len = tokc ? strlen(tokv[0]) : 0;
  443. matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
  444. for(item = items; item && item->text; item++) {
  445. for(i = 0; i < tokc; i++)
  446. if(!fstrstr(item->text, tokv[i]))
  447. break;
  448. if(i != tokc) /* not all tokens match */
  449. continue;
  450. /* exact matches go first, then prefixes, then substrings */
  451. if(!tokc || !fstrncmp(tokv[0], item->text, len+1))
  452. appenditem(item, &matches, &matchend);
  453. else if(!fstrncmp(tokv[0], item->text, len))
  454. appenditem(item, &lprefix, &prefixend);
  455. else
  456. appenditem(item, &lsubstr, &substrend);
  457. }
  458. if(lprefix) {
  459. if(matches) {
  460. matchend->right = lprefix;
  461. lprefix->left = matchend;
  462. }
  463. else
  464. matches = lprefix;
  465. matchend = prefixend;
  466. }
  467. if(lsubstr) {
  468. if(matches) {
  469. matchend->right = lsubstr;
  470. lsubstr->left = matchend;
  471. }
  472. else
  473. matches = lsubstr;
  474. matchend = substrend;
  475. }
  476. curr = sel = matches;
  477. calcoffsets();
  478. }
  479. size_t
  480. nextrune(int inc) {
  481. ssize_t n;
  482. /* return location of next utf8 rune in the given direction (+1 or -1) */
  483. for(n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc);
  484. return n;
  485. }
  486. void
  487. paste(void) {
  488. char *p, *q;
  489. int di;
  490. unsigned long dl;
  491. Atom da;
  492. /* we have been given the current selection, now insert it into input */
  493. XGetWindowProperty(dpy, win, utf8, 0, (sizeof text / 4) + 1, False,
  494. utf8, &da, &di, &dl, &dl, (unsigned char **)&p);
  495. insert(p, (q = strchr(p, '\n')) ? q-p : (ssize_t)strlen(p));
  496. XFree(p);
  497. drawmenu();
  498. }
  499. void
  500. readstdin(void) {
  501. char buf[sizeof text], *p, *maxstr = NULL;
  502. size_t i, max = 0, size = 0;
  503. /* read each line from stdin and add it to the item list */
  504. for(i = 0; fgets(buf, sizeof buf, stdin); i++) {
  505. if(i+1 >= size / sizeof *items)
  506. if(!(items = realloc(items, (size += BUFSIZ))))
  507. die("cannot realloc %u bytes:", size);
  508. if((p = strchr(buf, '\n')))
  509. *p = '\0';
  510. if(!(items[i].text = strdup(buf)))
  511. die("cannot strdup %u bytes:", strlen(buf)+1);
  512. items[i].out = false;
  513. if(strlen(items[i].text) > max)
  514. max = strlen(maxstr = items[i].text);
  515. }
  516. if(items)
  517. items[i].text = NULL;
  518. inputw = maxstr ? TEXTW(maxstr) : 0;
  519. lines = MIN(lines, i);
  520. }
  521. void
  522. run(void) {
  523. XEvent ev;
  524. while(!XNextEvent(dpy, &ev)) {
  525. if(XFilterEvent(&ev, win))
  526. continue;
  527. switch(ev.type) {
  528. case Expose:
  529. if(ev.xexpose.count == 0)
  530. drw_map(drw, win, 0, 0, mw, mh);
  531. break;
  532. case KeyPress:
  533. keypress(&ev.xkey);
  534. break;
  535. case SelectionNotify:
  536. if(ev.xselection.property == utf8)
  537. paste();
  538. break;
  539. case VisibilityNotify:
  540. if(ev.xvisibility.state != VisibilityUnobscured)
  541. XRaiseWindow(dpy, win);
  542. break;
  543. }
  544. }
  545. }
  546. void
  547. setup(void) {
  548. int x, y;
  549. XSetWindowAttributes swa;
  550. XIM xim;
  551. #ifdef XINERAMA
  552. XineramaScreenInfo *info;
  553. Window w, pw, dw, *dws;
  554. XWindowAttributes wa;
  555. int a, j, di, n, i = 0, area = 0;
  556. unsigned int du;
  557. #endif
  558. /* init appearance */
  559. scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
  560. scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
  561. scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
  562. scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
  563. scheme[SchemeOut].bg = drw_clr_create(drw, outbgcolor);
  564. scheme[SchemeOut].fg = drw_clr_create(drw, outfgcolor);
  565. clip = XInternAtom(dpy, "CLIPBOARD", False);
  566. utf8 = XInternAtom(dpy, "UTF8_STRING", False);
  567. /* calculate menu geometry */
  568. bh = drw->fonts[0]->h + 2;
  569. lines = MAX(lines, 0);
  570. mh = (lines + 1) * bh;
  571. #ifdef XINERAMA
  572. if((info = XineramaQueryScreens(dpy, &n))) {
  573. XGetInputFocus(dpy, &w, &di);
  574. if(mon != -1 && mon < n)
  575. i = mon;
  576. if(!i && w != root && w != PointerRoot && w != None) {
  577. /* find top-level window containing current input focus */
  578. do {
  579. if(XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
  580. XFree(dws);
  581. } while(w != root && w != pw);
  582. /* find xinerama screen with which the window intersects most */
  583. if(XGetWindowAttributes(dpy, pw, &wa))
  584. for(j = 0; j < n; j++)
  585. if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
  586. area = a;
  587. i = j;
  588. }
  589. }
  590. /* no focused window is on screen, so use pointer location instead */
  591. if(mon == -1 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
  592. for(i = 0; i < n; i++)
  593. if(INTERSECT(x, y, 1, 1, info[i]))
  594. break;
  595. x = info[i].x_org;
  596. y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
  597. mw = info[i].width;
  598. XFree(info);
  599. }
  600. else
  601. #endif
  602. {
  603. x = 0;
  604. y = topbar ? 0 : sh - mh;
  605. mw = sw;
  606. }
  607. promptw = (prompt && *prompt) ? TEXTW(prompt) : 0;
  608. inputw = MIN(inputw, mw/3);
  609. match();
  610. /* create menu window */
  611. swa.override_redirect = True;
  612. swa.background_pixel = scheme[SchemeNorm].bg->pix;
  613. swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
  614. win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
  615. DefaultDepth(dpy, screen), CopyFromParent,
  616. DefaultVisual(dpy, screen),
  617. CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
  618. /* open input methods */
  619. xim = XOpenIM(dpy, NULL, NULL, NULL);
  620. xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
  621. XNClientWindow, win, XNFocusWindow, win, NULL);
  622. XMapRaised(dpy, win);
  623. drw_resize(drw, mw, mh);
  624. drawmenu();
  625. }
  626. void
  627. usage(void) {
  628. fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
  629. " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
  630. exit(1);
  631. }