X-Git-Url: https://git.xinqibao.xyz/dmenu.git/blobdiff_plain/518c9b72d1c84bde7de49c2fb04c0d0a7cbe725b..8623bf5d196cb0bed4bdca025f23664b2bdcdd8b:/dmenu.c?ds=inline diff --git a/dmenu.c b/dmenu.c index f93407d..3fd9275 100644 --- a/dmenu.c +++ b/dmenu.c @@ -42,8 +42,8 @@ typedef struct { typedef struct Item Item; struct Item { char *text; - Item *next; /* traverses all items */ - Item *left, *right; /* traverses items matching current search pattern */ + Item *next; /* traverses all items */ + Item *left, *right; /* traverses items matching current search pattern */ }; /* forward declarations */ @@ -85,8 +85,8 @@ static unsigned int numlockmask = 0; static Bool running = True; static Display *dpy; static DC dc; -static Item *allitems = NULL; /* first of all items */ -static Item *item = NULL; /* first of pattern matching items */ +static Item *allitems = NULL; /* first of all items */ +static Item *item = NULL; /* first of pattern matching items */ static Item *sel = NULL; static Item *next = NULL; static Item *prev = NULL; @@ -212,12 +212,12 @@ drawmenu(void) { dc.h = mh; drawtext(NULL, dc.norm); /* print prompt? */ - if(promptw) { + if(prompt) { dc.w = promptw; drawtext(prompt, dc.sel); + dc.x += dc.w; } - dc.x += promptw; - dc.w = mw - promptw; + dc.w = mw - dc.x; /* print command */ if(cmdw && item && lines == 0) dc.w = cmdw; @@ -241,14 +241,13 @@ drawmenuh(void) { dc.w = spaceitem; drawtext(curr->left ? "<" : NULL, dc.norm); dc.x += dc.w; - /* determine maximum items */ for(i = curr; i != next; i=i->right) { dc.w = MIN(textw(i->text), mw / 3); drawtext(i->text, (sel == i) ? dc.sel : dc.norm); dc.x += dc.w; } - dc.x = mw - spaceitem; dc.w = spaceitem; + dc.x = mw - dc.w; drawtext(next ? ">" : NULL, dc.norm); } @@ -256,10 +255,8 @@ void drawmenuv(void) { Item *i; - dc.x = 0; - dc.w = mw; + dc.w = mw - dc.x; dc.y += dc.font.height + 2; - /* determine maximum items */ for(i = curr; i != next; i=i->right) { drawtext(i->text, (sel == i) ? dc.sel : dc.norm); dc.y += dc.font.height + 2; @@ -340,13 +337,11 @@ initfont(const char *fontstr) { if(missing) XFreeStringList(missing); if(dc.font.set) { - XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; dc.font.ascent = dc.font.descent = 0; - font_extents = XExtentsOfFontSet(dc.font.set); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); - for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { + for(i = 0; i < n; i++) { dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); dc.font.descent = MAX(dc.font.descent, (*xfonts)->descent); xfonts++;