diff options
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 49 |
1 files changed, 26 insertions, 23 deletions
@@ -55,26 +55,24 @@ static char text[4096]; | |||
55 | static int cmdw = 0; | 55 | static int cmdw = 0; |
56 | static int promptw = 0; | 56 | static int promptw = 0; |
57 | static int ret = 0; | 57 | static int ret = 0; |
58 | static int screen; | ||
58 | static unsigned int lines = 0; | 59 | static unsigned int lines = 0; |
59 | static unsigned int numlockmask = 0; | 60 | static unsigned int numlockmask = 0; |
61 | static unsigned int mw, mh; | ||
60 | static Bool running = True; | 62 | static Bool running = True; |
63 | static DC dc; | ||
64 | static Display *dpy; | ||
61 | static Item *allitems = NULL; /* first of all items */ | 65 | static Item *allitems = NULL; /* first of all items */ |
62 | static Item *item = NULL; /* first of pattern matching items */ | 66 | static Item *item = NULL; /* first of pattern matching items */ |
63 | static Item *sel = NULL; | 67 | static Item *sel = NULL; |
64 | static Item *next = NULL; | 68 | static Item *next = NULL; |
65 | static Item *prev = NULL; | 69 | static Item *prev = NULL; |
66 | static Item *curr = NULL; | 70 | static Item *curr = NULL; |
67 | static Window win; | 71 | static Window win, parent; |
68 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; | 72 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; |
69 | static char *(*fstrstr)(const char *, const char *) = strstr; | 73 | static char *(*fstrstr)(const char *, const char *) = strstr; |
70 | static void (*calcoffsets)(void) = calcoffsetsh; | 74 | static void (*calcoffsets)(void) = calcoffsetsh; |
71 | 75 | ||
72 | Display *dpy; | ||
73 | DC dc; | ||
74 | int screen; | ||
75 | unsigned int mw, mh; | ||
76 | Window parent; | ||
77 | |||
78 | void | 76 | void |
79 | appenditem(Item *i, Item **list, Item **last) { | 77 | appenditem(Item *i, Item **list, Item **last) { |
80 | if(!(*last)) | 78 | if(!(*last)) |
@@ -92,11 +90,11 @@ calcoffsetsh(void) { | |||
92 | 90 | ||
93 | w = promptw + cmdw + (2 * spaceitem); | 91 | w = promptw + cmdw + (2 * spaceitem); |
94 | for(next = curr; next; next = next->right) | 92 | for(next = curr; next; next = next->right) |
95 | if((w += MIN(textw(next->text), mw / 3)) > mw) | 93 | if((w += MIN(textw(&dc, next->text), mw / 3)) > mw) |
96 | break; | 94 | break; |
97 | w = promptw + cmdw + (2 * spaceitem); | 95 | w = promptw + cmdw + (2 * spaceitem); |
98 | for(prev = curr; prev && prev->left; prev = prev->left) | 96 | for(prev = curr; prev && prev->left; prev = prev->left) |
99 | if((w += MIN(textw(prev->left->text), mw / 3)) > mw) | 97 | if((w += MIN(textw(&dc, prev->left->text), mw / 3)) > mw) |
100 | break; | 98 | break; |
101 | } | 99 | } |
102 | 100 | ||
@@ -143,7 +141,7 @@ cleanup(void) { | |||
143 | free(allitems); | 141 | free(allitems); |
144 | allitems = itm; | 142 | allitems = itm; |
145 | } | 143 | } |
146 | drawcleanup(); | 144 | cleanupdraw(&dc); |
147 | XDestroyWindow(dpy, win); | 145 | XDestroyWindow(dpy, win); |
148 | XUngrabKeyboard(dpy, CurrentTime); | 146 | XUngrabKeyboard(dpy, CurrentTime); |
149 | } | 147 | } |
@@ -161,18 +159,18 @@ drawmenu(void) { | |||
161 | dc.y = 0; | 159 | dc.y = 0; |
162 | dc.w = mw; | 160 | dc.w = mw; |
163 | dc.h = mh; | 161 | dc.h = mh; |
164 | drawtext(NULL, dc.norm); | 162 | drawtext(&dc, NULL, dc.norm); |
165 | /* print prompt? */ | 163 | /* print prompt? */ |
166 | if(prompt) { | 164 | if(prompt) { |
167 | dc.w = promptw; | 165 | dc.w = promptw; |
168 | drawtext(prompt, dc.sel); | 166 | drawtext(&dc, prompt, dc.sel); |
169 | dc.x += dc.w; | 167 | dc.x += dc.w; |
170 | } | 168 | } |
171 | dc.w = mw - dc.x; | 169 | dc.w = mw - dc.x; |
172 | /* print command */ | 170 | /* print command */ |
173 | if(cmdw && item && lines == 0) | 171 | if(cmdw && item && lines == 0) |
174 | dc.w = cmdw; | 172 | dc.w = cmdw; |
175 | drawtext(*text ? text : NULL, dc.norm); | 173 | drawtext(&dc, *text ? text : NULL, dc.norm); |
176 | if(curr) { | 174 | if(curr) { |
177 | if(lines > 0) | 175 | if(lines > 0) |
178 | drawmenuv(); | 176 | drawmenuv(); |
@@ -189,16 +187,16 @@ drawmenuh(void) { | |||
189 | 187 | ||
190 | dc.x += cmdw; | 188 | dc.x += cmdw; |
191 | dc.w = spaceitem; | 189 | dc.w = spaceitem; |
192 | drawtext(curr->left ? "<" : NULL, dc.norm); | 190 | drawtext(&dc, curr->left ? "<" : NULL, dc.norm); |
193 | dc.x += dc.w; | 191 | dc.x += dc.w; |
194 | for(i = curr; i != next; i=i->right) { | 192 | for(i = curr; i != next; i=i->right) { |
195 | dc.w = MIN(textw(i->text), mw / 3); | 193 | dc.w = MIN(textw(&dc, i->text), mw / 3); |
196 | drawtext(i->text, (sel == i) ? dc.sel : dc.norm); | 194 | drawtext(&dc, i->text, (sel == i) ? dc.sel : dc.norm); |
197 | dc.x += dc.w; | 195 | dc.x += dc.w; |
198 | } | 196 | } |
199 | dc.w = spaceitem; | 197 | dc.w = spaceitem; |
200 | dc.x = mw - dc.w; | 198 | dc.x = mw - dc.w; |
201 | drawtext(next ? ">" : NULL, dc.norm); | 199 | drawtext(&dc, next ? ">" : NULL, dc.norm); |
202 | } | 200 | } |
203 | 201 | ||
204 | void | 202 | void |
@@ -209,11 +207,11 @@ drawmenuv(void) { | |||
209 | dc.h = dc.font.height + 2; | 207 | dc.h = dc.font.height + 2; |
210 | dc.y = dc.h; | 208 | dc.y = dc.h; |
211 | for(i = curr; i != next; i=i->right) { | 209 | for(i = curr; i != next; i=i->right) { |
212 | drawtext(i->text, (sel == i) ? dc.sel : dc.norm); | 210 | drawtext(&dc, i->text, (sel == i) ? dc.sel : dc.norm); |
213 | dc.y += dc.h; | 211 | dc.y += dc.h; |
214 | } | 212 | } |
215 | dc.h = mh - dc.y; | 213 | dc.h = mh - dc.y; |
216 | drawtext(NULL, dc.norm); | 214 | drawtext(&dc, NULL, dc.norm); |
217 | } | 215 | } |
218 | 216 | ||
219 | Bool | 217 | Bool |
@@ -491,7 +489,12 @@ setup(Bool topbar) { | |||
491 | } | 489 | } |
492 | XFreeModifiermap(modmap); | 490 | XFreeModifiermap(modmap); |
493 | 491 | ||
494 | initfont(font); | 492 | dc.dpy = dpy; |
493 | dc.norm[ColBG] = getcolor(&dc, normbgcolor); | ||
494 | dc.norm[ColFG] = getcolor(&dc, normfgcolor); | ||
495 | dc.sel[ColBG] = getcolor(&dc, selbgcolor); | ||
496 | dc.sel[ColFG] = getcolor(&dc, selfgcolor); | ||
497 | initfont(&dc, font); | ||
495 | 498 | ||
496 | /* menu window */ | 499 | /* menu window */ |
497 | wa.override_redirect = True; | 500 | wa.override_redirect = True; |
@@ -531,11 +534,11 @@ setup(Bool topbar) { | |||
531 | DefaultVisual(dpy, screen), | 534 | DefaultVisual(dpy, screen), |
532 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); | 535 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
533 | 536 | ||
534 | drawsetup(); | 537 | setupdraw(&dc, win); |
535 | if(maxname) | 538 | if(maxname) |
536 | cmdw = MIN(textw(maxname), mw / 3); | 539 | cmdw = MIN(textw(&dc, maxname), mw / 3); |
537 | if(prompt) | 540 | if(prompt) |
538 | promptw = MIN(textw(prompt), mw / 5); | 541 | promptw = MIN(textw(&dc, prompt), mw / 5); |
539 | text[0] = '\0'; | 542 | text[0] = '\0'; |
540 | match(text); | 543 | match(text); |
541 | XMapRaised(dpy, win); | 544 | XMapRaised(dpy, win); |