diff --git a/gadgets/config.mk b/gadgets/config.mk index b6fc39f..097b238 100644 --- a/gadgets/config.mk +++ b/gadgets/config.mk @@ -8,9 +8,22 @@ X11INC = /usr/X11R6/include INCS = -I. -I/usr/include -I${X11INC} X11LIB = /usr/X11R6/lib -LIBS = -L/usr/lib -CFLAGS = -Os ${INCS} +# Configure the features you want to be supported +# Only one of the following options has to be uncommented, +# all others must be commented! +# +# Uncomment: Remove # from the beginning of respective lines +# Comment : Add # to the beginning of the respective lines + +## Option 1: No XFT +#LIBS = -L/usr/lib +#CFLAGS = -Os ${INCS} + +## Option 2: With XFT +LIBS = -L/usr/lib `pkg-config --libs xft` +CFLAGS = -Os ${INCS} -DDZEN_XFT `pkg-config --cflags xft` + LDFLAGS = ${LIBS} # compiler and linker diff --git a/gadgets/textwidth.c b/gadgets/textwidth.c index 6f95f35..521bc0c 100644 --- a/gadgets/textwidth.c +++ b/gadgets/textwidth.c @@ -27,6 +27,9 @@ THE SOFTWARE. #include #include #include +#ifdef DZEN_XFT +#include +#endif typedef struct _Fnt { XFontStruct *xfont; @@ -34,6 +37,11 @@ typedef struct _Fnt { int ascent; int descent; int height; +#ifdef DZEN_XFT + XftFont *xftfont; + XGlyphInfo *extents; + int width; +#endif } Fnt; Fnt font; @@ -42,19 +50,25 @@ Display *dpy; unsigned int textw(const char *text, unsigned int len) { XRectangle r; - +#ifndef DZEN_XFT if(font.set) { XmbTextExtents(font.set, text, len, NULL, &r); return r.width; } return XTextWidth(font.xfont, text, len); +#else + XftTextExtentsUtf8(dpy, font.xftfont, (unsigned const char *) text, strlen(text), font.extents); + if(font.extents->height > font.height) + font.height = font.extents->height; + return font.extents->xOff; +#endif } void setfont(const char *fontstr) { +#ifndef DZEN_XFT char *def, **missing; int i, n; - missing = NULL; if(font.set) XFreeFontSet(dpy, font.set); @@ -88,6 +102,21 @@ setfont(const char *fontstr) { font.descent = font.xfont->descent; } font.height = font.ascent + font.descent; +#else + if(font.xftfont) + XftFontClose(dpy, font.xftfont); + font.xftfont = XftFontOpenXlfd(dpy, DefaultScreen(dpy), fontstr); + if(!font.xftfont) + font.xftfont = XftFontOpenName(dpy, DefaultScreen(dpy), fontstr); + if(!font.xftfont) { + fprintf(stderr, "error, cannot load font: '%s'\n", fontstr); + exit(EXIT_FAILURE); + } + font.extents = malloc(sizeof(XGlyphInfo)); + XftTextExtentsUtf8(dpy, font.xftfont, (unsigned const char *) fontstr, strlen(fontstr), font.extents); + font.height = font.xftfont->ascent + font.xftfont->descent; + font.width = (font.extents->width)/strlen(fontstr); +#endif } int