aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnselm R Garbe <anselm@garbe.us>2010-03-07 08:32:16 +0000
committerAnselm R Garbe <anselm@garbe.us>2010-03-07 08:32:16 +0000
commit37236f8840624d5e9d590e7be9ba365bc61913a6 (patch)
tree2ecdf8a89621ce83c5276ed8a8902669976c5ee1
parent7082ba1e1050664309de707bbc5b7194a53ed5ac (diff)
applied Connor's patch, thanks!
-rw-r--r--dmenu.c77
1 files changed, 33 insertions, 44 deletions
diff --git a/dmenu.c b/dmenu.c
index 1f7abca..aef8ae5 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -52,6 +52,7 @@ static void calcoffsetsh(void);
52static void calcoffsetsv(void); 52static void calcoffsetsv(void);
53static char *cistrstr(const char *s, const char *sub); 53static char *cistrstr(const char *s, const char *sub);
54static void cleanup(void); 54static void cleanup(void);
55static void drawmenu(void);
55static void drawmenuh(void); 56static void drawmenuh(void);
56static void drawmenuv(void); 57static void drawmenuv(void);
57static void drawtext(const char *text, unsigned long col[ColLast]); 58static void drawtext(const char *text, unsigned long col[ColLast]);
@@ -95,7 +96,6 @@ static char *(*fstrstr)(const char *, const char *) = strstr;
95static Bool vlist = False; 96static Bool vlist = False;
96static unsigned int lines = 5; 97static unsigned int lines = 5;
97static void (*calcoffsets)(void) = calcoffsetsh; 98static void (*calcoffsets)(void) = calcoffsetsh;
98static void (*drawmenu)(void) = drawmenuh;
99 99
100void 100void
101appenditem(Item *i, Item **list, Item **last) { 101appenditem(Item *i, Item **list, Item **last) {
@@ -200,7 +200,7 @@ cleanup(void) {
200 200
201void 201void
202drawcursor(void) { 202drawcursor(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
211void 211void
212drawmenuh(void) { 212drawmenu(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
253void 241void
242drawmenuh(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
261void
254drawmenuv(void) { 262drawmenuv(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
286void 276void
@@ -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];