From 15362de42b2b4603f928873aaaf31174381b97a9 Mon Sep 17 00:00:00 2001 From: phillbush Date: Wed, 29 Jul 2020 01:19:45 -0300 Subject: [PATCH] computing textwidth with the function drawtext --- xmenu.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/xmenu.c b/xmenu.c index 29ccb66..6305a13 100644 --- a/xmenu.c +++ b/xmenu.c @@ -731,12 +731,13 @@ drawitems(struct Menu *menu) static void setupitems(struct Menu *menu) { - XGlyphInfo ext; struct Item *item; - int itemwidth; menu->w = config.width_pixels; for (item = menu->list; item != NULL; item = item->next) { + int itemwidth; + int textwidth; + item->y = menu->h; if (item->label == NULL) /* height for separator item */ @@ -745,23 +746,24 @@ setupitems(struct Menu *menu) item->h = config.height_pixels; menu->h += item->h; - /* get length of item->label rendered in the font */ - XftTextExtentsUtf8(dpy, dc.fonts[0], (XftChar8 *)item->label, - item->labellen, &ext); + if (item->label) + textwidth = drawtext(NULL, NULL, 0, 0, item->h, item->label); + else + textwidth = 0; /* * set menu width * - * the item width depends on the size of its label (ext.xOff), + * the item width depends on the size of its label (textwidth), * and it is only used to calculate the width of the menu (which * is equal to the width of the largest item). * * the horizontal padding appears 4 times through the width of a - * item: before and after its icon, and before and after its triangle + * item: before and after its icon, and before and after its triangle. * if the iflag is set (icons are disabled) then the horizontal - * padding appears before the label and around the triangle. + * padding appears 3 times: before the label and around the triangle. */ - itemwidth = ext.xOff + config.triangle_width + config.horzpadding * 3; + itemwidth = textwidth + config.triangle_width + config.horzpadding * 3; itemwidth += (iflag) ? 0 : config.iconsize + config.horzpadding; menu->w = MAX(menu->w, itemwidth); }