From ce73dfea935f73b93cab3bf202450f4209c5fb03 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:38:20 +0000 Subject: [PATCH] move the 2 small font helper functions to xutil.c --- app/cwm/Makefile | 4 ++-- app/cwm/calmwm.h | 9 ++++---- app/cwm/font.c | 51 --------------------------------------------- app/cwm/menu.c | 12 +++++------ app/cwm/mousefunc.c | 7 ++++--- app/cwm/xutil.c | 22 ++++++++++++++++++- 6 files changed, 37 insertions(+), 68 deletions(-) delete mode 100644 app/cwm/font.c diff --git a/app/cwm/Makefile b/app/cwm/Makefile index a6c5ea81c..79469911e 100644 --- a/app/cwm/Makefile +++ b/app/cwm/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.19 2011/06/23 22:48:59 naddy Exp $ +# $OpenBSD: Makefile,v 1.20 2013/05/19 23:38:20 okan Exp $ .include @@ -6,7 +6,7 @@ PROG= cwm SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \ search.c util.c xutil.c conf.c xevents.c group.c \ - kbfunc.c mousefunc.c font.c parse.y + kbfunc.c mousefunc.c parse.y CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR} diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index 529d46307..5de748a61 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/calmwm.h @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: calmwm.h,v 1.204 2013/05/19 23:16:29 okan Exp $ + * $OpenBSD: calmwm.h,v 1.205 2013/05/19 23:38:21 okan Exp $ */ #ifndef _CALMWM_H_ @@ -444,10 +444,6 @@ void conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); -void font_draw(struct screen_ctx *, const char *, - Drawable, int, int, int); -int font_width(XftFont *, const char *, int); - void xev_loop(void); void xu_btn_grab(Window, int, u_int); @@ -466,6 +462,9 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); +void xu_xft_draw(struct screen_ctx *, const char *, + Drawable, int, int, int); +int xu_xft_width(XftFont *, const char *, int); void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); diff --git a/app/cwm/font.c b/app/cwm/font.c deleted file mode 100644 index de1f10f9b..000000000 --- a/app/cwm/font.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * calmwm - the calm window manager - * - * Copyright (c) 2005 Marius Eriksen - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $OpenBSD: font.c,v 1.28 2013/05/19 23:16:29 okan Exp $ - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "calmwm.h" - -int -font_width(XftFont *xftfont, const char *text, int len) -{ - XGlyphInfo extents; - - XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, - len, &extents); - - return (extents.xOff); -} - -void -font_draw(struct screen_ctx *sc, const char *text, - Drawable d, int color, int x, int y) -{ - XftDrawChange(sc->xftdraw, d); - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, - (const FcChar8*)text, strlen(text)); -} diff --git a/app/cwm/menu.c b/app/cwm/menu.c index 1e862ba1a..9468a810f 100644 --- a/app/cwm/menu.c +++ b/app/cwm/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.61 2013/05/14 12:35:56 okan Exp $ + * $OpenBSD: menu.c,v 1.62 2013/05/19 23:38:21 okan Exp $ */ #include @@ -367,7 +367,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->hasprompt) { (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); - mc->width = font_width(sc->xftfont, mc->dispstr, + mc->width = xu_xft_width(sc->xftfont, mc->dispstr, strlen(mc->dispstr)); mc->height = sc->xftfont->height + 1; mc->num = 1; @@ -384,7 +384,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, text = mi->text; } - mc->width = MAX(mc->width, font_width(sc->xftfont, text, + mc->width = MAX(mc->width, xu_xft_width(sc->xftfont, text, MIN(strlen(text), MENU_MAXENTRY))); mc->height += sc->xftfont->height + 1; mc->num++; @@ -419,7 +419,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, mc->width, mc->height); if (mc->hasprompt) { - font_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent); n = 1; } else @@ -434,7 +434,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->y + y > xine.h) break; - font_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); + xu_xft_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { @@ -466,7 +466,7 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - font_draw(sc, text, sc->menuwin, color, + xu_xft_draw(sc, text, sc->menuwin, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/app/cwm/mousefunc.c b/app/cwm/mousefunc.c index f16ca95b2..98b96dfc3 100644 --- a/app/cwm/mousefunc.c +++ b/app/cwm/mousefunc.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: mousefunc.c,v 1.50 2013/05/14 12:35:56 okan Exp $ + * $OpenBSD: mousefunc.c,v 1.51 2013/05/19 23:38:21 okan Exp $ */ #include @@ -58,11 +58,12 @@ mousefunc_sweep_draw(struct client_ctx *cc) XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, - font_width(sc->xftfont, asize, strlen(asize)), sc->xftfont->height); + xu_xft_width(sc->xftfont, asize, strlen(asize)), + sc->xftfont->height); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1); } diff --git a/app/cwm/xutil.c b/app/cwm/xutil.c index 0d22aa313..e8b8549aa 100644 --- a/app/cwm/xutil.c +++ b/app/cwm/xutil.c @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: xutil.c,v 1.62 2013/05/19 23:09:59 okan Exp $ + * $OpenBSD: xutil.c,v 1.63 2013/05/19 23:38:21 okan Exp $ */ #include @@ -429,3 +429,23 @@ xu_xorcolor(XftColor a, XftColor b, XftColor *r) r->color.blue = a.color.blue ^ b.color.blue; r->color.alpha = 0xffff; } + +int +xu_xft_width(XftFont *xftfont, const char *text, int len) +{ + XGlyphInfo extents; + + XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, + len, &extents); + + return (extents.xOff); +} + +void +xu_xft_draw(struct screen_ctx *sc, const char *text, + Drawable d, int color, int x, int y) +{ + XftDrawChange(sc->xftdraw, d); + XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, + x, y, (const FcChar8*)text, strlen(text)); +}