updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / dmenu-xft / dmenu-4.4-xft.patch
blob302e55e6943f84d42a7711dd524f3c219d06fc8d
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
4 @@ -2,19 +2,24 @@
5 VERSION = 4.4
7 # paths
8 -PREFIX = /usr/local
9 +PREFIX = /usr
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
24 # includes and libs
25 -INCS = -I${X11INC}
26 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
27 +INCS = -I${X11INC} -I${XFTINC}
28 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XFTLIBS}
30 # flags
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
36 @@ -16,6 +16,8 @@
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;
44 struct 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;
53 static Atom utf8;
54 static Bool topbar = True;
55 static DC *dc;
56 @@ -102,7 +104,9 @@ main(int argc, char *argv[]) {
57 usage();
59 dc = initdc();
60 - initfont(dc, font);
61 + initfont(dc, font ? font : DEFFONT);
62 + normcol = initcolor(dc, normfgcolor, normbgcolor);
63 + selcol = initcolor(dc, selfgcolor, selbgcolor);
65 if(fast) {
66 grabkeyboard();
67 @@ -165,7 +169,8 @@ drawmenu(void) {
68 dc->x = 0;
69 dc->y = 0;
70 dc->h = bh;
71 - drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
72 + drawrect(dc, 0, 0, mw, mh, True, normcol->BG);
75 if(prompt) {
76 dc->w = promptw;
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);
84 if(lines > 0) {
85 dc->w = mw - dc->x;
86 @@ -479,11 +484,12 @@ setup(void) {
87 XineramaScreenInfo *info;
88 #endif
90 + /*
91 normcol[ColBG] = getcolor(dc, normbgcolor);
92 normcol[ColFG] = getcolor(dc, normfgcolor);
93 selcol[ColBG] = getcolor(dc, selbgcolor);
94 selcol[ColFG] = getcolor(dc, selfgcolor);
96 +*/
97 utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
99 /* menu geometry */
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
104 @@ -5,13 +5,11 @@
105 #include <stdlib.h>
106 #include <string.h>
107 #include <X11/Xlib.h>
108 +#include <X11/Xft/Xft.h>
109 #include "draw.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);
117 void
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
122 void
123 -drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
124 +drawtext(DC *dc, const char *text, ColorSet *col) {
125 char buf[BUFSIZ];
126 size_t mn, n = strlen(text);
128 @@ -35,19 +33,25 @@ drawtext(DC *dc, const char *text, unsig
129 if(mn < n)
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);
138 void
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));
145 - if(dc->font.set)
146 - XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
147 - else {
148 + XSetForeground(dc->dpy, dc->gc, col->FG);
149 + if(dc->font.xft_font) {
150 + if (!dc->xftdraw)
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);
156 + } else {
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, ...) {
161 exit(EXIT_FAILURE);
164 + void
165 +freecol(DC *dc, ColorSet *col) {
166 + if(col) {
167 + if(&col->FG_xft)
168 + XftColorFree(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
169 + DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), &col->FG_xft);
170 + free(col);
175 void
176 freedc(DC *dc) {
177 + if(dc->font.xft_font) {
178 + XftFontClose(dc->dpy, dc->font.xft_font);
179 + XftDrawDestroy(dc->xftdraw);
181 if(dc->font.set)
182 XFreeFontSet(dc->dpy, dc->font.set);
183 if(dc->font.xfont)
184 XFreeFont(dc->dpy, dc->font.xfont);
185 if(dc->canvas)
186 XFreePixmap(dc->dpy, dc->canvas);
187 - XFreeGC(dc->dpy, dc->gc);
188 - XCloseDisplay(dc->dpy);
189 - free(dc);
190 + if(dc->gc)
191 + XFreeGC(dc->dpy, dc->gc);
192 + if(dc->dpy)
193 + XCloseDisplay(dc->dpy);
194 + if(dc)
195 + free(dc);
199 +ColorSet *
200 +initcolor(DC *dc, const char * foreground, const char * background) {
201 + ColorSet * col = (ColorSet *)malloc(sizeof(ColorSet));
202 + if(!col)
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);
210 + return col;
214 unsigned long
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) {
229 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;
240 -Bool
241 -loadfont(DC *dc, const char *fontstr) {
242 - char *def, **missing, **names;
243 + char *def, **missing=NULL, **names;
244 int i, n = 1;
245 XFontStruct **xfonts;
247 - if(!*fontstr)
248 - return False;
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;
258 + return;
259 + }
260 else
261 n = 0;
263 @@ -140,7 +175,7 @@ loadfont(DC *dc, const char *fontstr) {
265 if(missing)
266 XFreeStringList(missing);
267 - return (dc->font.set || dc->font.xfont);
268 + dc->font.height = dc->font.ascent + dc->font.descent;
271 void
272 @@ -150,6 +185,7 @@ mapdc(DC *dc, Window win, unsigned int w
274 void
275 resizedc(DC *dc, unsigned int w, unsigned int h) {
276 + int screen = DefaultScreen(dc->dpy);
277 if(dc->canvas)
278 XFreePixmap(dc->dpy, dc->canvas);
280 @@ -157,17 +193,30 @@ resizedc(DC *dc, unsigned int w, unsigne
281 dc->h = h;
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));
287 + if(!(dc->xftdraw))
288 + eprintf("error, cannot create xft drawable\n");
294 textnw(DC *dc, const char *text, size_t len) {
295 - if(dc->font.set) {
296 + if(dc->font.xft_font) {
297 + XGlyphInfo gi;
298 + XftTextExtentsUtf8(dc->dpy, dc->font.xft_font, (const FcChar8*)text, len, &gi);
299 + return gi.width;
300 + } else if(dc->font.set) {
301 XRectangle r;
303 XmbTextExtents(dc->font.set, text, len, NULL, &r);
304 return r.width;
306 - return XTextWidth(dc->font.xfont, text, len);
307 + } else {
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
317 @@ -1,9 +1,9 @@
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>
328 typedef struct {
329 int x, y, w, h;
330 @@ -11,6 +11,7 @@ typedef struct {
331 Display *dpy;
332 GC gc;
333 Pixmap canvas;
334 + XftDraw *xftdraw;
335 struct {
336 int ascent;
337 int descent;
338 @@ -18,12 +19,21 @@ typedef struct {
339 int width;
340 XFontSet set;
341 XFontStruct *xfont;
342 + XftFont *xft_font;
343 } font;
344 } DC; /* draw context */
346 +typedef struct {
347 + unsigned long FG;
348 + XftColor FG_xft;
349 + unsigned long BG;
350 +} ColorSet;
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, ...);
360 void freedc(DC *dc);
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