From 5f5374eb8ec00ff4d793c6a037f20dd2a1a91cd8 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 28 Sep 2016 17:06:33 +0000 Subject: Inline Xft draw and extents wrappers; too much abstraction. --- menu.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'menu.c') diff --git a/menu.c b/menu.c index 42a6077..a9de925 100644 --- a/menu.c +++ b/menu.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: menu.c,v 1.92 2016/09/20 19:58:54 okan Exp $ + * $OpenBSD: menu.c,v 1.93 2016/09/28 17:06:33 okan Exp $ */ #include @@ -334,6 +334,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) struct menu *mi; struct geom area; int n, xsave, ysave; + XGlyphInfo extents; if (mc->list) { if (TAILQ_EMPTY(resultq)) { @@ -352,8 +353,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->hasprompt) { (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); - mc->geom.w = xu_xft_width(sc->xftfont, mc->dispstr, - strlen(mc->dispstr)); + + XftTextExtentsUtf8(X_Dpy, sc->xftfont, + (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents); + + mc->geom.w = extents.xOff; mc->geom.h = sc->xftfont->height + 1; mc->num = 1; } @@ -365,8 +369,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) (void)snprintf(mi->print, sizeof(mi->print), "%s", mi->text); - mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont, - mi->print, MIN(strlen(mi->print), MENU_MAXENTRY))); + XftTextExtentsUtf8(X_Dpy, sc->xftfont, + (const FcChar8*)mi->print, + MIN(strlen(mi->print), MENU_MAXENTRY), &extents); + + mc->geom.w = MAX(mc->geom.w, extents.xOff); mc->geom.h += sc->xftfont->height + 1; mc->num++; } @@ -400,8 +407,10 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) mc->geom.w, mc->geom.h); if (mc->hasprompt) { - xu_xft_draw(sc, mc->dispstr, CWM_COLOR_MENU_FONT, - 0, sc->xftfont->ascent); + XftDrawStringUtf8(sc->xftdraw, + &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, + 0, sc->xftfont->ascent, + (const FcChar8*)mc->dispstr, strlen(mc->dispstr)); n = 1; } else n = 0; @@ -413,7 +422,10 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->geom.y + y > area.h) break; - xu_xft_draw(sc, mi->print, CWM_COLOR_MENU_FONT, 0, y); + XftDrawStringUtf8(sc->xftdraw, + &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, + 0, y, + (const FcChar8*)mi->print, strlen(mi->print)); n++; } if (mc->hasprompt && n > 1) @@ -442,8 +454,10 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, (sc->xftfont->height + 1) * entry, mc->geom.w, (sc->xftfont->height + 1) + sc->xftfont->descent); color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - xu_xft_draw(sc, mi->print, color, - 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); + XftDrawStringUtf8(sc->xftdraw, + &sc->xftcolor[color], sc->xftfont, + 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1, + (const FcChar8*)mi->print, strlen(mi->print)); } static void -- cgit v1.2.3-2-gb3c3