new libdraw
53761130
1 file(s) · +25 −25
| 80 | 80 | if(lines > 0) |
|
| 81 | 81 | n = lines * bh; |
|
| 82 | 82 | else |
|
| 83 | - | n = mw - (promptw + inputw + textw(dc, "<") + textw(dc, ">")); |
|
| 83 | + | n = mw - (promptw + inputw + dc_textw(dc, "<") + dc_textw(dc, ">")); |
|
| 84 | 84 | ||
| 85 | 85 | for(i = 0, next = curr; next; next = next->right) |
|
| 86 | - | if((i += (lines > 0) ? bh : MIN(textw(dc, next->text), mw/3)) > n) |
|
| 86 | + | if((i += (lines > 0) ? bh : MIN(dc_textw(dc, next->text), mw/3)) > n) |
|
| 87 | 87 | break; |
|
| 88 | 88 | for(i = 0, prev = curr; prev && prev->left; prev = prev->left) |
|
| 89 | - | if((i += (lines > 0) ? bh : MIN(textw(dc, prev->left->text), mw/3)) > n) |
|
| 89 | + | if((i += (lines > 0) ? bh : MIN(dc_textw(dc, prev->left->text), mw/3)) > n) |
|
| 90 | 90 | break; |
|
| 91 | 91 | } |
|
| 92 | 92 | ||
| 98 | 98 | dc->x = 0; |
|
| 99 | 99 | dc->y = 0; |
|
| 100 | 100 | dc->h = bh; |
|
| 101 | - | drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol)); |
|
| 101 | + | dc_drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol)); |
|
| 102 | 102 | ||
| 103 | 103 | if(prompt) { |
|
| 104 | 104 | dc->w = promptw; |
|
| 105 | - | drawtext(dc, prompt, selcol); |
|
| 105 | + | dc_drawtext(dc, prompt, selcol); |
|
| 106 | 106 | dc->x = dc->w; |
|
| 107 | 107 | } |
|
| 108 | 108 | dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw; |
|
| 109 | - | drawtext(dc, text, normcol); |
|
| 110 | - | if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w) |
|
| 111 | - | drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol)); |
|
| 109 | + | dc_drawtext(dc, text, normcol); |
|
| 110 | + | if((curpos = dc_textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w) |
|
| 111 | + | dc_drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol)); |
|
| 112 | 112 | ||
| 113 | 113 | if(lines > 0) { |
|
| 114 | 114 | dc->w = mw - dc->x; |
|
| 115 | 115 | for(item = curr; item != next; item = item->right) { |
|
| 116 | 116 | dc->y += dc->h; |
|
| 117 | - | drawtext(dc, item->text, (item == sel) ? selcol : normcol); |
|
| 117 | + | dc_drawtext(dc, item->text, (item == sel) ? selcol : normcol); |
|
| 118 | 118 | } |
|
| 119 | 119 | } |
|
| 120 | 120 | else if(matches) { |
|
| 121 | 121 | dc->x += inputw; |
|
| 122 | - | dc->w = textw(dc, "<"); |
|
| 122 | + | dc->w = dc_textw(dc, "<"); |
|
| 123 | 123 | if(curr->left) |
|
| 124 | - | drawtext(dc, "<", normcol); |
|
| 124 | + | dc_drawtext(dc, "<", normcol); |
|
| 125 | 125 | for(item = curr; item != next; item = item->right) { |
|
| 126 | 126 | dc->x += dc->w; |
|
| 127 | - | dc->w = MIN(textw(dc, item->text), mw/3); |
|
| 128 | - | drawtext(dc, item->text, (item == sel) ? selcol : normcol); |
|
| 127 | + | dc->w = MIN(dc_textw(dc, item->text), mw/3); |
|
| 128 | + | dc_drawtext(dc, item->text, (item == sel) ? selcol : normcol); |
|
| 129 | 129 | } |
|
| 130 | - | dc->w = textw(dc, ">"); |
|
| 130 | + | dc->w = dc_textw(dc, ">"); |
|
| 131 | 131 | dc->x = mw - dc->w; |
|
| 132 | 132 | if(next) |
|
| 133 | - | drawtext(dc, ">", normcol); |
|
| 133 | + | dc_drawtext(dc, ">", normcol); |
|
| 134 | 134 | } |
|
| 135 | - | mapdraw(dc, win, mw, mh); |
|
| 135 | + | dc_map(dc, win, mw, mh); |
|
| 136 | 136 | } |
|
| 137 | 137 | ||
| 138 | 138 | char * |
|
| 396 | 396 | if(!(item->text = strdup(buf))) |
|
| 397 | 397 | eprintf("cannot strdup %u bytes\n", strlen(buf)+1); |
|
| 398 | 398 | item->next = item->left = item->right = NULL; |
|
| 399 | - | inputw = MAX(inputw, textw(dc, item->text)); |
|
| 399 | + | inputw = MAX(inputw, dc_textw(dc, item->text)); |
|
| 400 | 400 | } |
|
| 401 | 401 | } |
|
| 402 | 402 | ||
| 437 | 437 | root = RootWindow(dc->dpy, screen); |
|
| 438 | 438 | utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); |
|
| 439 | 439 | ||
| 440 | - | normcol[ColBG] = getcolor(dc, normbgcolor); |
|
| 441 | - | normcol[ColFG] = getcolor(dc, normfgcolor); |
|
| 442 | - | selcol[ColBG] = getcolor(dc, selbgcolor); |
|
| 443 | - | selcol[ColFG] = getcolor(dc, selfgcolor); |
|
| 440 | + | normcol[ColBG] = dc_color(dc, normbgcolor); |
|
| 441 | + | normcol[ColFG] = dc_color(dc, normfgcolor); |
|
| 442 | + | selcol[ColBG] = dc_color(dc, selbgcolor); |
|
| 443 | + | selcol[ColFG] = dc_color(dc, selfgcolor); |
|
| 444 | 444 | ||
| 445 | 445 | /* menu geometry */ |
|
| 446 | 446 | bh = dc->font.height + 2; |
|
| 478 | 478 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
|
| 479 | 479 | ||
| 480 | 480 | grabkeyboard(); |
|
| 481 | - | resizedraw(dc, mw, mh); |
|
| 481 | + | dc_resize(dc, mw, mh); |
|
| 482 | 482 | inputw = MIN(inputw, mw/3); |
|
| 483 | - | promptw = prompt ? MIN(textw(dc, prompt), mw/5) : 0; |
|
| 483 | + | promptw = prompt ? MIN(dc_textw(dc, prompt), mw/5) : 0; |
|
| 484 | 484 | XMapRaised(dc->dpy, win); |
|
| 485 | 485 | text[0] = '\0'; |
|
| 486 | 486 | match(); |
|
| 528 | 528 | else |
|
| 529 | 529 | usage(); |
|
| 530 | 530 | ||
| 531 | - | dc = initdraw(); |
|
| 532 | - | initfont(dc, font); |
|
| 531 | + | dc = dc_init(); |
|
| 532 | + | dc_font(dc, font); |
|
| 533 | 533 | readstdin(); |
|
| 534 | 534 | setup(); |
|
| 535 | 535 | run(); |
|