1 diff -rup dmenu-4.4/config.mk dmenu-4.4-xft/config.mk
2 --- dmenu-4.4/config.mk 2011-07-20 02:01:28.000000000 +0530
3 +++ dmenu-4.4-xft/config.mk 2011-08-03 21:46:43.767914223 +0530
10 MANPREFIX = ${PREFIX}/share/man
12 X11INC = /usr/X11R6/include
13 X11LIB = /usr/X11R6/lib
15 +# Xft, comment if you don't want it
16 +XFTINC = /usr/include/freetype2
17 +XFTLIBS = -lXft -lXrender -lfreetype -lz -lfontconfig
20 # Xinerama, comment if you don't want it
21 XINERAMALIBS = -lXinerama
22 XINERAMAFLAGS = -DXINERAMA
26 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
27 +INCS = -I${X11INC} -I${XFTINC}
28 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XFTLIBS}
31 CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
32 Only in dmenu-4.4-xft: dmenu
33 diff -rup dmenu-4.4/dmenu.c dmenu-4.4-xft/dmenu.c
34 --- dmenu-4.4/dmenu.c 2011-07-20 02:01:28.000000000 +0530
35 +++ dmenu-4.4-xft/dmenu.c 2011-08-03 21:38:49.000000000 +0530
37 #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
38 #define MIN(a,b) ((a) < (b) ? (a) : (b))
39 #define MAX(a,b) ((a) > (b) ? (a) : (b))
40 +#define DEFFONT "fixed" /* xft example: "Monospace-11" */
43 typedef struct Item Item;
45 @@ -49,8 +51,8 @@ static const char *normbgcolor = "#ccccc
46 static const char *normfgcolor = "#000000";
47 static const char *selbgcolor = "#0066ff";
48 static const char *selfgcolor = "#ffffff";
49 -static unsigned long normcol[ColLast];
50 -static unsigned long selcol[ColLast];
51 +static ColorSet *normcol;
52 +static ColorSet *selcol;
54 static Bool topbar = True;
56 @@ -102,7 +104,9 @@ main(int argc, char *argv[]) {
61 + initfont(dc, font ? font : DEFFONT);
62 + normcol = initcolor(dc, normfgcolor, normbgcolor);
63 + selcol = initcolor(dc, selfgcolor, selbgcolor);
67 @@ -165,7 +169,8 @@ drawmenu(void) {
71 - drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
72 + drawrect(dc, 0, 0, mw, mh, True, normcol->BG);
77 @@ -175,7 +180,7 @@ drawmenu(void) {
78 dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
79 drawtext(dc, text, normcol);
80 if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
81 - drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol));
82 + drawrect(dc, curpos, 2, 1, dc->h - 4, True, normcol->FG);
86 @@ -479,11 +484,12 @@ setup(void) {
87 XineramaScreenInfo *info;
91 normcol[ColBG] = getcolor(dc, normbgcolor);
92 normcol[ColFG] = getcolor(dc, normfgcolor);
93 selcol[ColBG] = getcolor(dc, selbgcolor);
94 selcol[ColFG] = getcolor(dc, selfgcolor);
97 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
100 Only in dmenu-4.4-xft: dmenu.o
101 diff -rup dmenu-4.4/draw.c dmenu-4.4-xft/draw.c
102 --- dmenu-4.4/draw.c 2011-07-20 02:01:28.000000000 +0530
103 +++ dmenu-4.4-xft/draw.c 2011-08-03 21:38:49.000000000 +0530
107 #include <X11/Xlib.h>
108 +#include <X11/Xft/Xft.h>
111 #define MAX(a, b) ((a) > (b) ? (a) : (b))
112 #define MIN(a, b) ((a) < (b) ? (a) : (b))
113 -#define DEFAULTFN "fixed"
115 -static Bool loadfont(DC *dc, const char *fontstr);
118 drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
119 @@ -23,7 +21,7 @@ drawrect(DC *dc, int x, int y, unsigned
123 -drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
124 +drawtext(DC *dc, const char *text, ColorSet *col) {
126 size_t mn, n = strlen(text);
128 @@ -35,19 +33,25 @@ drawtext(DC *dc, const char *text, unsig
130 for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
132 - drawrect(dc, 0, 0, dc->w, dc->h, True, BG(dc, col));
133 +drawrect(dc, 0, 0, dc->w, dc->h, True, col->BG);
135 drawtextn(dc, buf, mn, col);
139 -drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) {
140 +drawtextn(DC *dc, const char *text, size_t n, ColorSet *col) {
141 int x = dc->x + dc->font.height/2;
142 int y = dc->y + dc->font.ascent+1;
144 - XSetForeground(dc->dpy, dc->gc, FG(dc, col));
146 - XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
148 + XSetForeground(dc->dpy, dc->gc, col->FG);
149 + if(dc->font.xft_font) {
151 + eprintf("error, xft drawable does not exist");
152 + XftDrawStringUtf8(dc->xftdraw, &col->FG_xft,
153 + dc->font.xft_font, x, y, (unsigned char*)text, n);
154 + } else if(dc->font.set) {
155 + XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
157 XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
158 XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
160 @@ -68,19 +72,53 @@ eprintf(const char *fmt, ...) {
165 +freecol(DC *dc, ColorSet *col) {
168 + XftColorFree(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
169 + DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), &col->FG_xft);
177 + if(dc->font.xft_font) {
178 + XftFontClose(dc->dpy, dc->font.xft_font);
179 + XftDrawDestroy(dc->xftdraw);
182 XFreeFontSet(dc->dpy, dc->font.set);
184 XFreeFont(dc->dpy, dc->font.xfont);
186 XFreePixmap(dc->dpy, dc->canvas);
187 - XFreeGC(dc->dpy, dc->gc);
188 - XCloseDisplay(dc->dpy);
191 + XFreeGC(dc->dpy, dc->gc);
193 + XCloseDisplay(dc->dpy);
200 +initcolor(DC *dc, const char * foreground, const char * background) {
201 + ColorSet * col = (ColorSet *)malloc(sizeof(ColorSet));
203 + eprintf("error, cannot allocate memory for color set");
204 + col->BG = getcolor(dc, background);
205 + col->FG = getcolor(dc, foreground);
206 + if(dc->font.xft_font)
207 + if(!XftColorAllocName(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
208 + DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), foreground, &col->FG_xft))
209 + eprintf("error, cannot allocate xft font color '%s'\n", foreground);
215 getcolor(DC *dc, const char *colstr) {
216 Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
217 @@ -101,6 +139,9 @@ initdc(void) {
218 eprintf("cannot malloc %u bytes:", sizeof *dc);
219 if(!(dc->dpy = XOpenDisplay(NULL)))
220 eprintf("cannot open display\n");
221 + dc->font.xft_font = NULL;
222 + dc->xftdraw = NULL;
225 dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
226 XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter);
227 @@ -109,27 +150,21 @@ initdc(void) {
230 initfont(DC *dc, const char *fontstr) {
231 - if(!loadfont(dc, fontstr ? fontstr : DEFAULTFN)) {
232 - if(fontstr != NULL)
233 - fprintf(stderr, "cannot load font '%s'\n", fontstr);
234 - if(fontstr == NULL || !loadfont(dc, DEFAULTFN))
235 - eprintf("cannot load font '%s'\n", DEFAULTFN);
237 - dc->font.height = dc->font.ascent + dc->font.descent;
241 -loadfont(DC *dc, const char *fontstr) {
242 - char *def, **missing, **names;
243 + char *def, **missing=NULL, **names;
245 XFontStruct **xfonts;
249 if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def)))
250 n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
251 else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr)))
252 xfonts = &dc->font.xfont;
253 + else if((dc->font.xft_font = XftFontOpenName(dc->dpy,
254 + DefaultScreen(dc->dpy), fontstr))) {
255 + dc->font.ascent = dc->font.xft_font->ascent;
256 + dc->font.descent = dc->font.xft_font->descent;
257 + dc->font.height = dc->font.ascent + dc->font.descent;
263 @@ -140,7 +175,7 @@ loadfont(DC *dc, const char *fontstr) {
266 XFreeStringList(missing);
267 - return (dc->font.set || dc->font.xfont);
268 + dc->font.height = dc->font.ascent + dc->font.descent;
272 @@ -150,6 +185,7 @@ mapdc(DC *dc, Window win, unsigned int w
275 resizedc(DC *dc, unsigned int w, unsigned int h) {
276 + int screen = DefaultScreen(dc->dpy);
278 XFreePixmap(dc->dpy, dc->canvas);
280 @@ -157,17 +193,30 @@ resizedc(DC *dc, unsigned int w, unsigne
282 dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
283 DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
285 + if(dc->font.xft_font && !(dc->xftdraw)) {
286 + dc->xftdraw = XftDrawCreate(dc->dpy, dc->canvas, DefaultVisual(dc->dpy,screen), DefaultColormap(dc->dpy,screen));
288 + eprintf("error, cannot create xft drawable\n");
294 textnw(DC *dc, const char *text, size_t len) {
296 + if(dc->font.xft_font) {
298 + XftTextExtentsUtf8(dc->dpy, dc->font.xft_font, (const FcChar8*)text, len, &gi);
300 + } else if(dc->font.set) {
303 XmbTextExtents(dc->font.set, text, len, NULL, &r);
306 - return XTextWidth(dc->font.xfont, text, len);
308 + return XTextWidth(dc->font.xfont, text, len);
314 diff -rup dmenu-4.4/draw.h dmenu-4.4-xft/draw.h
315 --- dmenu-4.4/draw.h 2011-07-20 02:01:28.000000000 +0530
316 +++ dmenu-4.4-xft/draw.h 2011-08-03 21:38:49.000000000 +0530
318 /* See LICENSE file for copyright and license details. */
320 -#define FG(dc, col) ((col)[(dc)->invert ? ColBG : ColFG])
321 -#define BG(dc, col) ((col)[(dc)->invert ? ColFG : ColBG])
323 -enum { ColBG, ColFG, ColBorder, ColLast };
325 +#include <X11/Xft/Xft.h>
330 @@ -11,6 +11,7 @@ typedef struct {
338 @@ -18,12 +19,21 @@ typedef struct {
344 } DC; /* draw context */
353 void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
354 -void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
355 -void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
356 +void drawtext(DC *dc, const char *text, ColorSet *col);
357 +void drawtextn(DC *dc, const char *text, size_t n, ColorSet *col);
358 +void freecol(DC *dc, ColorSet *col);
359 void eprintf(const char *fmt, ...);
361 unsigned long getcolor(DC *dc, const char *colstr);
362 @@ -33,3 +43,6 @@ void mapdc(DC *dc, Window win, unsigned
363 void resizedc(DC *dc, unsigned int w, unsigned int h);
364 int textnw(DC *dc, const char *text, size_t len);
365 int textw(DC *dc, const char *text);
366 +ColorSet *initcolor(DC *dc, const char *foreground, const char *background);
369 Only in dmenu-4.4-xft: draw.o
370 Only in dmenu-4.4-xft: lsx
371 Only in dmenu-4.4-xft: lsx.o