aboutsummaryrefslogtreecommitdiff
path: root/dmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/dmenu.c b/dmenu.c
index f0be02a..9d6088b 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -10,7 +10,7 @@
10#ifdef XINERAMA 10#ifdef XINERAMA
11#include <X11/extensions/Xinerama.h> 11#include <X11/extensions/Xinerama.h>
12#endif 12#endif
13#include <dc.h> 13#include "draw.h"
14 14
15#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) 15#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
16#define MIN(a,b) ((a) < (b) ? (a) : (b)) 16#define MIN(a,b) ((a) < (b) ? (a) : (b))
@@ -81,13 +81,13 @@ calcoffsets(void) {
81 if(lines > 0) 81 if(lines > 0)
82 n = lines * bh; 82 n = lines * bh;
83 else 83 else
84 n = mw - (promptw + inputw + dc_textw(dc, "<") + dc_textw(dc, ">")); 84 n = mw - (promptw + inputw + textw(dc, "<") + textw(dc, ">"));
85 85
86 for(i = 0, next = curr; next; next = next->right) 86 for(i = 0, next = curr; next; next = next->right)
87 if((i += (lines > 0) ? bh : MIN(dc_textw(dc, next->text), n)) > n) 87 if((i += (lines > 0) ? bh : MIN(textw(dc, next->text), n)) > n)
88 break; 88 break;
89 for(i = 0, prev = curr; prev && prev->left; prev = prev->left) 89 for(i = 0, prev = curr; prev && prev->left; prev = prev->left)
90 if((i += (lines > 0) ? bh : MIN(dc_textw(dc, prev->left->text), n)) > n) 90 if((i += (lines > 0) ? bh : MIN(textw(dc, prev->left->text), n)) > n)
91 break; 91 break;
92} 92}
93 93
@@ -99,41 +99,41 @@ drawmenu(void) {
99 dc->x = 0; 99 dc->x = 0;
100 dc->y = 0; 100 dc->y = 0;
101 dc->h = bh; 101 dc->h = bh;
102 dc_drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol)); 102 drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
103 103
104 if(prompt) { 104 if(prompt) {
105 dc->w = promptw; 105 dc->w = promptw;
106 dc_drawtext(dc, prompt, selcol); 106 drawtext(dc, prompt, selcol);
107 dc->x = dc->w; 107 dc->x = dc->w;
108 } 108 }
109 dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw; 109 dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
110 dc_drawtext(dc, text, normcol); 110 drawtext(dc, text, normcol);
111 if((curpos = dc_textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w) 111 if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
112 dc_drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol)); 112 drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol));
113 113
114 if(lines > 0) { 114 if(lines > 0) {
115 dc->w = mw - dc->x; 115 dc->w = mw - dc->x;
116 for(item = curr; item != next; item = item->right) { 116 for(item = curr; item != next; item = item->right) {
117 dc->y += dc->h; 117 dc->y += dc->h;
118 dc_drawtext(dc, item->text, (item == sel) ? selcol : normcol); 118 drawtext(dc, item->text, (item == sel) ? selcol : normcol);
119 } 119 }
120 } 120 }
121 else if(matches) { 121 else if(matches) {
122 dc->x += inputw; 122 dc->x += inputw;
123 dc->w = dc_textw(dc, "<"); 123 dc->w = textw(dc, "<");
124 if(curr->left) 124 if(curr->left)
125 dc_drawtext(dc, "<", normcol); 125 drawtext(dc, "<", normcol);
126 for(item = curr; item != next; item = item->right) { 126 for(item = curr; item != next; item = item->right) {
127 dc->x += dc->w; 127 dc->x += dc->w;
128 dc->w = MIN(dc_textw(dc, item->text), mw - dc->x - dc_textw(dc, ">")); 128 dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">"));
129 dc_drawtext(dc, item->text, (item == sel) ? selcol : normcol); 129 drawtext(dc, item->text, (item == sel) ? selcol : normcol);
130 } 130 }
131 dc->w = dc_textw(dc, ">"); 131 dc->w = textw(dc, ">");
132 dc->x = mw - dc->w; 132 dc->x = mw - dc->w;
133 if(next) 133 if(next)
134 dc_drawtext(dc, ">", normcol); 134 drawtext(dc, ">", normcol);
135 } 135 }
136 dc_map(dc, win, mw, mh); 136 mapdc(dc, win, mw, mh);
137} 137}
138 138
139char * 139char *
@@ -398,7 +398,7 @@ readstdin(void) {
398 if(!(item->text = strdup(buf))) 398 if(!(item->text = strdup(buf)))
399 eprintf("cannot strdup %u bytes\n", strlen(buf)+1); 399 eprintf("cannot strdup %u bytes\n", strlen(buf)+1);
400 item->next = item->left = item->right = NULL; 400 item->next = item->left = item->right = NULL;
401 inputw = MAX(inputw, dc_textw(dc, item->text)); 401 inputw = MAX(inputw, textw(dc, item->text));
402 } 402 }
403} 403}
404 404
@@ -439,10 +439,10 @@ setup(void) {
439 root = RootWindow(dc->dpy, screen); 439 root = RootWindow(dc->dpy, screen);
440 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); 440 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
441 441
442 normcol[ColBG] = dc_color(dc, normbgcolor); 442 normcol[ColBG] = getcolor(dc, normbgcolor);
443 normcol[ColFG] = dc_color(dc, normfgcolor); 443 normcol[ColFG] = getcolor(dc, normfgcolor);
444 selcol[ColBG] = dc_color(dc, selbgcolor); 444 selcol[ColBG] = getcolor(dc, selbgcolor);
445 selcol[ColFG] = dc_color(dc, selfgcolor); 445 selcol[ColFG] = getcolor(dc, selfgcolor);
446 446
447 /* menu geometry */ 447 /* menu geometry */
448 bh = dc->font.height + 2; 448 bh = dc->font.height + 2;
@@ -481,9 +481,9 @@ setup(void) {
481 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 481 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
482 482
483 grabkeyboard(); 483 grabkeyboard();
484 dc_resize(dc, mw, mh); 484 resizedc(dc, mw, mh);
485 inputw = MIN(inputw, mw/3); 485 inputw = MIN(inputw, mw/3);
486 promptw = prompt ? dc_textw(dc, prompt) : 0; 486 promptw = prompt ? textw(dc, prompt) : 0;
487 XMapRaised(dc->dpy, win); 487 XMapRaised(dc->dpy, win);
488 text[0] = '\0'; 488 text[0] = '\0';
489 match(); 489 match();
@@ -533,8 +533,8 @@ main(int argc, char *argv[]) {
533 else 533 else
534 usage(); 534 usage();
535 535
536 dc = dc_init(); 536 dc = initdc();
537 dc_font(dc, font); 537 initfont(dc, font);
538 readstdin(); 538 readstdin();
539 setup(); 539 setup();
540 run(); 540 run();