# HG changeset patch # Parent 5dfc8094dc1ccbb1de0e32588ef0ba6b7525637c diff -r 5dfc8094dc1c config.def.h --- a/config.def.h Sun Oct 14 00:45:07 2012 +0900 +++ b/config.def.h Sun Oct 14 00:52:26 2012 +0900 @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -static const char font[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; +static const char font[] = "monospace-9"; static const char normbgcolor[] = "#222222"; static const char normfgcolor[] = "#bbbbbb"; static const char selbgcolor[] = "#005577"; diff -r 5dfc8094dc1c config.mk --- a/config.mk Sun Oct 14 00:45:07 2012 +0900 +++ b/config.mk Sun Oct 14 00:52:26 2012 +0900 @@ -9,7 +9,7 @@ # includes and libs INCS = -I. -I/usr/include -LIBS = -L/usr/lib -lc -lX11 +LIBS = -L/usr/lib -lc -lXft -lX11 # flags CPPFLAGS = -DVERSION=\"${VERSION}\" diff -r 5dfc8094dc1c tabbed.c --- a/tabbed.c Sun Oct 14 00:45:07 2012 +0900 +++ b/tabbed.c Sun Oct 14 00:52:26 2012 +0900 @@ -15,6 +15,7 @@ #include #include #include +#include #include "arg.h" @@ -63,16 +64,15 @@ typedef struct { int x, y, w, h; - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; + XftColor norm[ColLast]; + XftColor sel[ColLast]; Drawable drawable; GC gc; struct { int ascent; int descent; int height; - XFontSet set; - XFontStruct *xfont; + XftFont *xfont; } font; } DC; /* draw context */ @@ -95,14 +95,14 @@ static void destroynotify(const XEvent *e); static void die(const char *errstr, ...); static void drawbar(); -static void drawtext(const char *text, unsigned long col[ColLast]); +static void drawtext(const char *text, XftColor col[ColLast]); static void *emallocz(size_t size); static void expose(const XEvent *e); static void focus(Client *c); static void focusin(const XEvent *e); static void focusonce(const Arg *arg); static Client *getclient(Window w); -static unsigned long getcolor(const char *colstr); +static XftColor getcolor(const char *colstr); static Client *getfirsttab(); static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); static void initfont(const char *fontstr); @@ -200,10 +200,6 @@ n = c->next; unmanage(c); } - 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); @@ -282,7 +278,7 @@ void drawbar() { - unsigned long *col; + XftColor *col; int n, width; Client *c, *fc; char *name = NULL; @@ -334,12 +330,13 @@ } void -drawtext(const char *text, unsigned long col[ColLast]) { +drawtext(const char *text, XftColor col[ColLast]) { int i, x, y, h, len, olen; char buf[256]; + XftDraw *d; XRectangle r = { dc.x, dc.y, dc.w, dc.h }; - XSetForeground(dpy, dc.gc, col[ColBG]); + XSetForeground(dpy, dc.gc, col[ColBG].pixel); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); if(!text) return; @@ -354,11 +351,12 @@ memcpy(buf, text, len); if(len < olen) for(i = len; i && i > len - 3; buf[--i] = '.'); - 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); + XSetForeground(dpy, dc.gc, col[ColFG].pixel); + + d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen)); + + XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len); + XftDrawDestroy(d); } void * @@ -432,14 +430,13 @@ return NULL; } -unsigned long +XftColor getcolor(const char *colstr) { - Colormap cmap = DefaultColormap(dpy, screen); - XColor color; + XftColor color; - if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) + if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color)) die("tabbed: cannot allocate color '%s'\n", colstr); - return color.pixel; + return color; } Client * @@ -486,39 +483,11 @@ void initfont(const char *fontstr) { - char *def, **missing; - int i, n; + if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr)) && !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed"))) + die("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) { - while(n--) - fprintf(stderr, "tabbed: missing fontset: %s\n", missing[n]); - XFreeStringList(missing); - } - if(dc.font.set) { - XFontStruct **xfonts; - char **font_names; - dc.font.ascent = dc.font.descent = 0; - n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); - for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { - dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); - dc.font.descent = MAX(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"))) - die("tabbed: cannot load font: '%s'\n", fontstr); - dc.font.ascent = dc.font.xfont->ascent; - dc.font.descent = dc.font.xfont->descent; - } + dc.font.ascent = dc.font.xfont->ascent; + dc.font.descent = dc.font.xfont->descent; dc.font.height = dc.font.ascent + dc.font.descent; } @@ -752,10 +721,8 @@ dc.sel[ColFG] = getcolor(selfgcolor); dc.drawable = XCreatePixmap(dpy, root, ww, wh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); - if(!dc.font.set) - XSetFont(dpy, dc.gc, dc.font.xfont->fid); - win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0, dc.norm[ColFG], dc.norm[ColBG]); + win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0, dc.norm[ColFG].pixel, dc.norm[ColBG].pixel); XMapRaised(dpy, win); XSelectInput(dpy, win, SubstructureNotifyMask|FocusChangeMask| ButtonPressMask|ExposureMask|KeyPressMask| @@ -798,13 +765,9 @@ 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); + XGlyphInfo ext; + XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext); + return ext.xOff; } void