1 diff -u dwm_original/config.def.h dwm_xft/config.def.h
2 --- dwm_original/config.def.h 2012-01-09 19:07:41.065029408 +0400
3 +++ dwm_xft/config.def.h 2012-01-09 19:02:02.313506614 +0400
5 /* See LICENSE file for copyright and license details. */
8 -static const char font[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
9 +static const char font[] = "Sans 8";
10 static const char normbordercolor[] = "#444444";
11 static const char normbgcolor[] = "#222222";
12 static const char normfgcolor[] = "#bbbbbb";
13 diff -u dwm_original/config.mk dwm_xft/config.mk
14 --- dwm_original/config.mk 2012-01-09 19:07:41.065029408 +0400
15 +++ dwm_xft/config.mk 2012-01-09 19:03:39.721464085 +0400
17 XINERAMAFLAGS = -DXINERAMA
20 -INCS = -I. -I/usr/include -I${X11INC}
21 -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
22 +INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags xft pango pangoxft`
23 +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} `pkg-config --libs xft pango pangoxft`
26 CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
27 diff -u dwm_original/dwm.c dwm_xft/dwm.c
28 --- dwm_original/dwm.c 2012-01-09 19:07:41.065029408 +0400
29 +++ dwm_xft/dwm.c 2012-01-09 19:07:17.705012468 +0400
32 #include <X11/Xproto.h>
33 #include <X11/Xutil.h>
34 +#include <X11/Xft/Xft.h>
35 +#include <pango/pango.h>
36 +#include <pango/pangoxft.h>
37 +#include <pango/pango-font.h>
39 #include <X11/extensions/Xinerama.h>
42 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
43 #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
44 #define LENGTH(X) (sizeof X / sizeof X[0])
45 -#define MAX(A, B) ((A) > (B) ? (A) : (B))
47 +#define MAX(A, B) ((A) > (B) ? (A) : (B))
50 #define MIN(A, B) ((A) < (B) ? (A) : (B))
52 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
53 #define WIDTH(X) ((X)->w + 2 * (X)->bw)
54 #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
56 unsigned long sel[ColLast];
60 + XftColor xftnorm[ColLast];
61 + XftColor xftsel[ColLast];
62 + XftDraw *xftdrawable;
66 + PangoFontDescription *pfd;
75 } DC; /* draw context */
78 static void focusin(XEvent *e);
79 static void focusmon(const Arg *arg);
80 static void focusstack(const Arg *arg);
81 -static unsigned long getcolor(const char *colstr);
82 +//static unsigned long getcolor(const char *colstr);
83 static Bool getrootptr(int *x, int *y);
84 static long getstate(Window w);
85 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
87 for(m = mons; m; m = m->next)
89 unmanage(m->stack, False);
91 - XFreeFontSet(dpy, dc.font.set);
93 - XFreeFont(dpy, dc.font.xfont);
94 XUngrabKey(dpy, AnyKey, AnyModifier, root);
95 XFreePixmap(dpy, dc.drawable);
99 XFreePixmap(dpy, dc.drawable);
100 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
101 + XftDrawChange(dc.xftdrawable, dc.drawable);
103 for(m = mons; m; m = m->next)
104 XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
108 h = dc.font.ascent + dc.font.descent;
109 - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
112 /* shorten text if necessary */
113 for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
115 memcpy(buf, text, len);
117 for(i = len; i && i > len - 3; buf[--i] = '.');
118 - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
120 - XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
122 - XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
123 + pango_layout_set_text(dc.plo, text, len);
124 + pango_xft_render_layout(dc.xftdrawable, (col==dc.norm?dc.xftnorm:dc.xftsel)+(invert?ColBG:ColFG), dc.plo, x * PANGO_SCALE, y * PANGO_SCALE);
128 @@ -927,13 +936,13 @@
132 -getcolor(const char *colstr) {
133 +getcolor(const char *colstr, XftColor *color) {
134 Colormap cmap = DefaultColormap(dpy, screen);
136 + Visual *vis = DefaultVisual(dpy, screen);
138 - if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
139 + if(!XftColorAllocName(dpy,vis,cmap,colstr, color))
140 die("error, cannot allocate color '%s'\n", colstr);
141 - return color.pixel;
142 + return color->pixel;
146 @@ -1034,35 +1043,19 @@
149 initfont(const char *fontstr) {
150 - char *def, **missing;
152 + PangoFontMetrics *metrics;
154 - dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
157 - fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
158 - XFreeStringList(missing);
161 - XFontStruct **xfonts;
164 - dc.font.ascent = dc.font.descent = 0;
165 - XExtentsOfFontSet(dc.font.set);
166 - n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
168 - dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
169 - dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
174 - if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
175 - && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
176 - die("error, cannot load font: '%s'\n", fontstr);
177 - dc.font.ascent = dc.font.xfont->ascent;
178 - dc.font.descent = dc.font.xfont->descent;
180 + dc.pgc = pango_xft_get_context(dpy, screen);
181 + dc.pfd = pango_font_description_from_string(fontstr);
183 + metrics = pango_context_get_metrics(dc.pgc, dc.pfd, pango_language_from_string(setlocale(LC_CTYPE, "")));
184 + dc.font.ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
185 + dc.font.descent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
187 + pango_font_metrics_unref(metrics);
189 + dc.plo = pango_layout_new(dc.pgc);
190 + pango_layout_set_font_description(dc.plo, dc.pfd);
191 dc.font.height = dc.font.ascent + dc.font.descent;
194 @@ -1611,19 +1604,24 @@
195 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
196 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
197 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
199 /* init appearance */
200 - dc.norm[ColBorder] = getcolor(normbordercolor);
201 - dc.norm[ColBG] = getcolor(normbgcolor);
202 - dc.norm[ColFG] = getcolor(normfgcolor);
203 - dc.sel[ColBorder] = getcolor(selbordercolor);
204 - dc.sel[ColBG] = getcolor(selbgcolor);
205 - dc.sel[ColFG] = getcolor(selfgcolor);
206 + dc.norm[ColBorder] = getcolor(normbordercolor, dc.xftnorm+ColBorder);
207 + dc.norm[ColBG] = getcolor(normbgcolor, dc.xftnorm+ColBG);
208 + dc.norm[ColFG] = getcolor(normfgcolor, dc.xftnorm+ColFG);
209 + dc.sel[ColBorder] = getcolor(selbordercolor, dc.xftsel+ColBorder);
210 + dc.sel[ColBG] = getcolor(selbgcolor, dc.xftsel+ColBG);
211 + dc.sel[ColFG] = getcolor(selfgcolor, dc.xftsel+ColFG);
213 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
214 dc.gc = XCreateGC(dpy, root, 0, NULL);
215 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
217 - XSetFont(dpy, dc.gc, dc.font.xfont->fid);
220 + dc.xftdrawable = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy,screen), DefaultColormap(dpy,screen));
221 + if(!dc.xftdrawable)
222 + printf("error, cannot create drawable\n");
227 /* EWMH support per view */
228 @@ -1692,13 +1690,10 @@
231 textnw(const char *text, unsigned int len) {
235 - XmbTextExtents(dc.font.set, text, len, NULL, &r);
238 - return XTextWidth(dc.font.xfont, text, len);
240 + pango_layout_set_text(dc.plo, text, len);
241 + pango_layout_get_extents(dc.plo, &r, 0);
242 + return r.width / PANGO_SCALE;