diff options
-rw-r--r-- | dmenu.c | 77 |
1 files changed, 33 insertions, 44 deletions
@@ -52,6 +52,7 @@ static void calcoffsetsh(void); | |||
52 | static void calcoffsetsv(void); | 52 | static void calcoffsetsv(void); |
53 | static char *cistrstr(const char *s, const char *sub); | 53 | static char *cistrstr(const char *s, const char *sub); |
54 | static void cleanup(void); | 54 | static void cleanup(void); |
55 | static void drawmenu(void); | ||
55 | static void drawmenuh(void); | 56 | static void drawmenuh(void); |
56 | static void drawmenuv(void); | 57 | static void drawmenuv(void); |
57 | static void drawtext(const char *text, unsigned long col[ColLast]); | 58 | static void drawtext(const char *text, unsigned long col[ColLast]); |
@@ -95,7 +96,6 @@ static char *(*fstrstr)(const char *, const char *) = strstr; | |||
95 | static Bool vlist = False; | 96 | static Bool vlist = False; |
96 | static unsigned int lines = 5; | 97 | static unsigned int lines = 5; |
97 | static void (*calcoffsets)(void) = calcoffsetsh; | 98 | static void (*calcoffsets)(void) = calcoffsetsh; |
98 | static void (*drawmenu)(void) = drawmenuh; | ||
99 | 99 | ||
100 | void | 100 | void |
101 | appenditem(Item *i, Item **list, Item **last) { | 101 | appenditem(Item *i, Item **list, Item **last) { |
@@ -200,7 +200,7 @@ cleanup(void) { | |||
200 | 200 | ||
201 | void | 201 | void |
202 | drawcursor(void) { | 202 | drawcursor(void) { |
203 | XRectangle r = { dc.x, dc.y + 2, 1, dc.h - 4 }; | 203 | XRectangle r = { dc.x, dc.y + 2, 1, dc.font.height - 2 }; |
204 | 204 | ||
205 | r.x += textnw(text, cursor) + dc.font.height / 2; | 205 | r.x += textnw(text, cursor) + dc.font.height / 2; |
206 | 206 | ||
@@ -209,9 +209,7 @@ drawcursor(void) { | |||
209 | } | 209 | } |
210 | 210 | ||
211 | void | 211 | void |
212 | drawmenuh(void) { | 212 | drawmenu(void) { |
213 | Item *i; | ||
214 | |||
215 | dc.x = 0; | 213 | dc.x = 0; |
216 | dc.y = 0; | 214 | dc.y = 0; |
217 | dc.w = mw; | 215 | dc.w = mw; |
@@ -231,56 +229,48 @@ drawmenuh(void) { | |||
231 | drawcursor(); | 229 | drawcursor(); |
232 | dc.x += cmdw; | 230 | dc.x += cmdw; |
233 | if(curr) { | 231 | if(curr) { |
234 | dc.w = spaceitem; | 232 | if(vlist) |
235 | drawtext((curr && curr->left) ? "<" : NULL, dc.norm); | 233 | drawmenuv(); |
236 | dc.x += dc.w; | 234 | else |
237 | /* determine maximum items */ | 235 | drawmenuh(); |
238 | for(i = curr; i != next; i=i->right) { | ||
239 | dc.w = textw(i->text); | ||
240 | if(dc.w > mw / 3) | ||
241 | dc.w = mw / 3; | ||
242 | drawtext(i->text, (sel == i) ? dc.sel : dc.norm); | ||
243 | dc.x += dc.w; | ||
244 | } | ||
245 | dc.x = mw - spaceitem; | ||
246 | dc.w = spaceitem; | ||
247 | drawtext(next ? ">" : NULL, dc.norm); | ||
248 | } | 236 | } |
249 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 237 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); |
250 | XFlush(dpy); | 238 | XFlush(dpy); |
251 | } | 239 | } |
252 | 240 | ||
253 | void | 241 | void |
242 | drawmenuh(void) { | ||
243 | Item *i; | ||
244 | |||
245 | dc.w = spaceitem; | ||
246 | drawtext((curr && curr->left) ? "<" : NULL, dc.norm); | ||
247 | dc.x += dc.w; | ||
248 | /* determine maximum items */ | ||
249 | for(i = curr; i != next; i=i->right) { | ||
250 | dc.w = textw(i->text); | ||
251 | if(dc.w > mw / 3) | ||
252 | dc.w = mw / 3; | ||
253 | drawtext(i->text, (sel == i) ? dc.sel : dc.norm); | ||
254 | dc.x += dc.w; | ||
255 | } | ||
256 | dc.x = mw - spaceitem; | ||
257 | dc.w = spaceitem; | ||
258 | drawtext(next ? ">" : NULL, dc.norm); | ||
259 | } | ||
260 | |||
261 | void | ||
254 | drawmenuv(void) { | 262 | drawmenuv(void) { |
255 | Item *i; | 263 | Item *i; |
256 | 264 | ||
257 | dc.x = 0; | 265 | dc.x = 0; |
258 | dc.y = 0; | ||
259 | dc.w = mw; | 266 | dc.w = mw; |
260 | dc.h = mh; | 267 | dc.y += dc.font.height + 2; |
261 | drawtext(NULL, dc.norm); | 268 | /* determine maximum items */ |
262 | /* print prompt? */ | 269 | for(i = curr; i != next; i=i->right) { |
263 | if(promptw) { | 270 | drawtext(i->text, (sel == i) ? dc.sel : dc.norm); |
264 | dc.w = promptw; | ||
265 | drawtext(prompt, dc.sel); | ||
266 | } | ||
267 | dc.x += promptw; | ||
268 | dc.w = mw - promptw; | ||
269 | /* print command */ | ||
270 | drawtext(text[0] ? text : NULL, dc.norm); | ||
271 | if(curr) { | ||
272 | dc.x = 0; | ||
273 | dc.w = mw; | ||
274 | dc.y += dc.font.height + 2; | 271 | dc.y += dc.font.height + 2; |
275 | /* determine maximum items */ | ||
276 | for(i = curr; i != next; i=i->right) { | ||
277 | drawtext(i->text, (sel == i) ? dc.sel : dc.norm); | ||
278 | dc.y += dc.font.height + 2; | ||
279 | } | ||
280 | drawtext(NULL, dc.norm); | ||
281 | } | 272 | } |
282 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 273 | drawtext(NULL, dc.norm); |
283 | XFlush(dpy); | ||
284 | } | 274 | } |
285 | 275 | ||
286 | void | 276 | void |
@@ -786,8 +776,7 @@ main(int argc, char *argv[]) { | |||
786 | else if(!strcmp(argv[i], "-l")) { | 776 | else if(!strcmp(argv[i], "-l")) { |
787 | vlist = True; | 777 | vlist = True; |
788 | calcoffsets = calcoffsetsv; | 778 | calcoffsets = calcoffsetsv; |
789 | drawmenu = drawmenuv; | 779 | if(++i < argc) lines = atoi(argv[i]); |
790 | if(++i < argc) lines += atoi(argv[i]); | ||
791 | } | 780 | } |
792 | else if(!strcmp(argv[i], "-fn")) { | 781 | else if(!strcmp(argv[i], "-fn")) { |
793 | if(++i < argc) font = argv[i]; | 782 | if(++i < argc) font = argv[i]; |