X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=menu.c;h=2392ed502bae72c095c764fe8c4c639335ff9036;hp=d2e50ecf2cda5dad8ab212a34932c6d6fcb537f8;hb=dfd84f9bf3b9d949412a73bc62a43109b340d395;hpb=3a69c5173cdd24959410870bec2a10a76272e034 diff --git a/menu.c b/menu.c index d2e50ec..2392ed5 100644 --- a/menu.c +++ b/menu.c @@ -31,24 +31,23 @@ struct Item { static Display *dpy; static Window root; static Window win; -static XRectangle rect; static Bool done = False; -static Item *allitem = 0; /* first of all items */ -static Item *item = 0; /* first of pattern matching items */ -static Item *sel = 0; -static Item *nextoff = 0; -static Item *prevoff = 0; -static Item *curroff = 0; +static Item *allitem = NULL; /* first of all items */ +static Item *item = NULL; /* first of pattern matching items */ +static Item *sel = NULL; +static Item *nextoff = NULL; +static Item *prevoff = NULL; +static Item *curroff = NULL; -static int screen; -static char *title = 0; +static int screen, mx, my, mw, mh; +static char *title = NULL; static char text[4096]; static int ret = 0; static int nitem = 0; static unsigned int cmdw = 0; -static unsigned int twidth = 0; -static unsigned int cwidth = 0; +static unsigned int tw = 0; +static unsigned int cw = 0; static const int seek = 30; /* 30px */ static Brush brush = {0}; @@ -74,21 +73,21 @@ update_offsets() return; for(nextoff = curroff; nextoff; nextoff=nextoff->right) { - tw = textwidth(&brush.font, nextoff->text); - if(tw > rect.width / 3) - tw = rect.width / 3; + tw = textw(&brush.font, nextoff->text); + if(tw > mw / 3) + tw = mw / 3; w += tw + brush.font.height; - if(w > rect.width) + if(w > mw) break; } w = cmdw + 2 * seek; for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) { - tw = textwidth(&brush.font, prevoff->left->text); - if(tw > rect.width / 3) - tw = rect.width / 3; + tw = textw(&brush.font, prevoff->left->text); + if(tw > mw / 3) + tw = mw / 3; w += tw + brush.font.height; - if(w > rect.width) + if(w > mw) break; } } @@ -103,11 +102,11 @@ update_items(char *pattern) return; if(!title || *pattern) - cmdw = cwidth; + cmdw = cw; else - cmdw = twidth; + cmdw = tw; - item = j = 0; + item = j = NULL; nitem = 0; for(i = allitem; i; i=i->next) @@ -117,7 +116,7 @@ update_items(char *pattern) else j->right = i; i->left = j; - i->right = 0; + i->right = NULL; j = i; nitem++; } @@ -129,7 +128,7 @@ update_items(char *pattern) else j->right = i; i->left = j; - i->right = 0; + i->right = NULL; j = i; nitem++; } @@ -143,42 +142,40 @@ update_items(char *pattern) static void draw_menu() { - unsigned int offx = 0; Item *i; - brush.rect = rect; - brush.rect.x = 0; - brush.rect.y = 0; + brush.x = 0; + brush.y = 0; + brush.w = mw; + brush.h = mh; draw(dpy, &brush, False, 0); /* print command */ if(!title || text[0]) { - cmdw = cwidth; + cmdw = cw; if(cmdw && item) - brush.rect.width = cmdw; + brush.w = cmdw; draw(dpy, &brush, False, text); } else { - cmdw = twidth; - brush.rect.width = cmdw; + cmdw = tw; + brush.w = cmdw; draw(dpy, &brush, False, title); } - offx += brush.rect.width; + brush.x += brush.w; if(curroff) { - brush.rect.x = offx; - brush.rect.width = seek; - offx += brush.rect.width; + brush.w = seek; draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0); + brush.x += brush.w; /* determine maximum items */ for(i = curroff; i != nextoff; i=i->right) { brush.border = False; - brush.rect.x = offx; - brush.rect.width = textwidth(&brush.font, i->text); - if(brush.rect.width > rect.width / 3) - brush.rect.width = rect.width / 3; - brush.rect.width += brush.font.height; + brush.w = textw(&brush.font, i->text); + if(brush.w > mw / 3) + brush.w = mw / 3; + brush.w += brush.font.height; if(sel == i) { swap((void **)&brush.fg, (void **)&brush.bg); draw(dpy, &brush, True, i->text); @@ -186,15 +183,14 @@ draw_menu() } else draw(dpy, &brush, False, i->text); - offx += brush.rect.width; + brush.x += brush.w; } - brush.rect.x = rect.width - seek; - brush.rect.width = seek; + brush.x = mw - seek; + brush.w = seek; draw(dpy, &brush, False, nextoff ? ">" : 0); } - XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width, - rect.height, 0, 0); + XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0); XFlush(dpy); } @@ -304,7 +300,7 @@ kpress(XKeyEvent * e) } break; default: - if((num == 1) && !iscntrl((int) buf[0])) { + if(num && !iscntrl((int) buf[0])) { buf[num] = 0; if(len > 0) strncat(text, buf, sizeof(text)); @@ -319,7 +315,7 @@ kpress(XKeyEvent * e) static char * read_allitems() { - static char *maxname = 0; + static char *maxname = NULL; char *p, buf[1024]; unsigned int len = 0, max = 0; Item *i, *new; @@ -336,7 +332,7 @@ read_allitems() } new = emalloc(sizeof(Item)); - new->next = new->left = new->right = 0; + new->next = new->left = new->right = NULL; new->text = p; if(!i) allitem = new; @@ -356,15 +352,6 @@ main(int argc, char *argv[]) char *maxname; XEvent ev; - char buf[256]; - - fputs(STATUSCMD, stdout); - fputs("\n", stdout); - pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD); - fputs(buf, stderr); - - return 0; - /* command line args */ for(i = 1; i < argc; i++) { if (argv[i][0] == '-') @@ -408,36 +395,35 @@ main(int argc, char *argv[]) wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; - rect.width = DisplayWidth(dpy, screen); - rect.height = labelheight(&brush.font); - rect.y = DisplayHeight(dpy, screen) - rect.height; - rect.x = 0; + mx = my = 0; + mw = DisplayWidth(dpy, screen); + mh = texth(&brush.font); - win = XCreateWindow(dpy, root, rect.x, rect.y, - rect.width, rect.height, 0, DefaultDepth(dpy, screen), - CopyFromParent, DefaultVisual(dpy, screen), + win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, + DefaultDepth(dpy, screen), CopyFromParent, + DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); XFlush(dpy); /* pixmap */ brush.gc = XCreateGC(dpy, root, 0, 0); - brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height, + brush.drawable = XCreatePixmap(dpy, win, mw, mh, DefaultDepth(dpy, screen)); XFlush(dpy); if(maxname) - cwidth = textwidth(&brush.font, maxname) + brush.font.height; - if(cwidth > rect.width / 3) - cwidth = rect.width / 3; + cw = textw(&brush.font, maxname) + brush.font.height; + if(cw > mw / 3) + cw = mw / 3; if(title) { - twidth = textwidth(&brush.font, title) + brush.font.height; - if(twidth > rect.width / 3) - twidth = rect.width / 3; + tw = textw(&brush.font, title) + brush.font.height; + if(tw > mw / 3) + tw = mw / 3; } - cmdw = title ? twidth : cwidth; + cmdw = title ? tw : cw; text[0] = 0; update_items(text);