diff -ur dmenu-3.4/config.h dmenu-xft-240/config.h --- dmenu-3.4/config.h 2007-10-25 22:26:14.000000000 +0400 +++ dmenu-xft-240/config.h 2008-02-10 02:13:25.000000000 +0300 @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -#define FONT "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*" +#define FONT "fixed-12" #define NORMBGCOLOR "#cccccc" #define NORMFGCOLOR "#000000" #define SELBGCOLOR "#0066ff" diff -ur dmenu-3.4/config.mk dmenu-xft-240/config.mk --- dmenu-3.4/config.mk 2007-10-25 22:26:14.000000000 +0400 +++ dmenu-xft-240/config.mk 2008-02-10 02:13:25.000000000 +0300 @@ -1,5 +1,5 @@ # dmenu version -VERSION = 3.4 +VERSION = 3.4xft # Customize below to fit your system @@ -11,8 +11,8 @@ X11LIB = /usr/X11R6/lib # includes and libs -INCS = -I. -I/usr/include -I${X11INC} -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 +INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags xft` +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs xft` # flags CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" diff -ur dmenu-3.4/dmenu.c dmenu-xft-240/dmenu.c --- dmenu-3.4/dmenu.c 2007-10-25 22:26:14.000000000 +0400 +++ dmenu-xft-240/dmenu.c 2008-02-10 02:13:25.000000000 +0300 @@ -9,7 +9,7 @@ #include #include #include - +#include /* macros */ #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) @@ -21,14 +21,16 @@ int x, y, w, h; unsigned long norm[ColLast]; unsigned long sel[ColLast]; + XftColor *xftnorm; + XftColor *xftsel; Drawable drawable; + XftDraw *xftdrawable; GC gc; struct { - XFontStruct *xfont; - XFontSet set; - int ascent; - int descent; + XftFont *xftfont; + XGlyphInfo *extents; int height; + int width; } font; } DC; /* draw context */ @@ -142,10 +144,6 @@ free(allitems); allitems = itm; } - if(dc.font.set) - XFreeFontSet(dpy, dc.font.set); - else - XFreeFont(dpy, dc.font.xfont); XFreePixmap(dpy, dc.drawable); XFreeGC(dpy, dc.gc); XDestroyWindow(dpy, win); @@ -210,11 +210,11 @@ len = sizeof buf - 1; memcpy(buf, text, len); buf[len] = 0; - h = dc.font.ascent + dc.font.descent; - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; - x = dc.x + (h / 2); + h = dc.font.height; + y = mh/2 + h/2; + x = dc.x+h/2; /* shorten text if necessary */ - while(len && (w = textnw(buf, len)) > dc.w - h) + while(len && (w = textnw(buf,len)) > dc.w) buf[--len] = 0; if(len < olen) { if(len > 1) @@ -227,10 +227,7 @@ if(w > dc.w) return; /* too long */ XSetForeground(dpy, dc.gc, col[ColFG]); - if(dc.font.set) - XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); - else - XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); + XftDrawStringUtf8(dc.xftdrawable, (col==dc.norm) ? dc.xftnorm : dc.xftsel ,dc.font.xftfont,x,y,buf,len); } void * @@ -289,40 +286,18 @@ char *def, **missing; int i, n; + if(!fontstr || fontstr[0] == '\0') eprint("error, cannot load font: '%s'\n", fontstr); - missing = NULL; - if(dc.font.set) - XFreeFontSet(dpy, dc.font.set); - dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); - 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++) { - if(dc.font.ascent < (*xfonts)->ascent) - dc.font.ascent = (*xfonts)->ascent; - if(dc.font.descent < (*xfonts)->descent) - dc.font.descent = (*xfonts)->descent; - xfonts++; - } - } - else { - if(dc.font.xfont) - XFreeFont(dpy, dc.font.xfont); - dc.font.xfont = NULL; - if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) - && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) - eprint("error, cannot load font: '%s'\n", fontstr); - dc.font.ascent = dc.font.xfont->ascent; - dc.font.descent = dc.font.xfont->descent; - } - dc.font.height = dc.font.ascent + dc.font.descent; + dc.font.xftfont = XftFontOpenXlfd(dpy,screen,fontstr); + if(!dc.font.xftfont) + dc.font.xftfont = XftFontOpenName(dpy,screen,fontstr); + if(!dc.font.xftfont) + eprint("error, cannot load font: '%s'\n", fontstr); + dc.font.extents = malloc(sizeof(XGlyphInfo)); + XftTextExtentsUtf8(dpy,dc.font.xftfont,fontstr, strlen(fontstr), dc.font.extents); + dc.font.height = dc.font.extents->y+dc.font.extents->yOff; + dc.font.width = (dc.font.extents->width)/strlen(fontstr); } void @@ -589,6 +564,12 @@ dc.norm[ColFG] = getcolor(normfg); dc.sel[ColBG] = getcolor(selbg); dc.sel[ColFG] = getcolor(selfg); + dc.xftsel=malloc(sizeof(XftColor)); + dc.xftnorm=malloc(sizeof(XftColor)); + XftColorAllocName(dpy,DefaultVisual(dpy,screen),DefaultColormap(dpy,screen),selfg, dc.xftsel); + XftColorAllocName(dpy,DefaultVisual(dpy,screen),DefaultColormap(dpy,screen),normfg, dc.xftnorm); + if(!dc.xftnorm || !dc.xftnorm) + eprint("error, cannot allocate color\n"); initfont(font); /* menu window */ @@ -596,7 +577,7 @@ wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; mw = DisplayWidth(dpy, screen); - mh = dc.font.height + 2; + mh = dc.font.extents->y+dc.font.extents->height - 1; win = XCreateWindow(dpy, root, 0, bottom ? DisplayHeight(dpy, screen) - mh : 0, mw, mh, 0, DefaultDepth(dpy, screen), CopyFromParent, @@ -604,11 +585,14 @@ CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); /* pixmap */ + dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); - if(!dc.font.set) - XSetFont(dpy, dc.gc, dc.font.xfont->fid); + + dc.xftdrawable = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy,screen),DefaultColormap(dpy,screen)); + if(!dc.xftdrawable) + eprint("error, cannot create drawable\n"); if(maxname) cmdw = textw(maxname); if(cmdw > mw / 3) @@ -655,18 +642,15 @@ unsigned int textnw(const char *text, unsigned int len) { - XRectangle r; - - if(dc.font.set) { - XmbTextExtents(dc.font.set, text, len, NULL, &r); - return r.width; - } - return XTextWidth(dc.font.xfont, text, len); + XftTextExtentsUtf8(dpy,dc.font.xftfont,text, strlen(text), dc.font.extents); + if(dc.font.extents->height > dc.font.height) + dc.font.height = dc.font.extents->height; + return dc.font.extents->width; } unsigned int textw(const char *text) { - return textnw(text, strlen(text)) + dc.font.height; + return textnw(text, strlen(text)) + 2*dc.font.width; } int