tabbed-0.6-xft.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
tabbed-0.6-xft.diff (6605B) | |
--- | |
1 diff --git a/config.def.h b/config.def.h | |
2 index ceda9f7..bc7cfe2 100644 | |
3 --- a/config.def.h | |
4 +++ b/config.def.h | |
5 @@ -1,7 +1,7 @@ | |
6 /* See LICENSE file for copyright and license details. */ | |
7 | |
8 /* appearance */ | |
9 -static const char font[] = "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*"; | |
10 +static const char font[] = "monospace-9"; | |
11 static const char* normbgcolor = "#222222"; | |
12 static const char* normfgcolor = "#cccccc"; | |
13 static const char* selbgcolor = "#555555"; | |
14 diff --git a/config.mk b/config.mk | |
15 index 5279711..037f9d7 100644 | |
16 --- a/config.mk | |
17 +++ b/config.mk | |
18 @@ -8,8 +8,8 @@ PREFIX = /usr/local | |
19 MANPREFIX = ${PREFIX}/share/man | |
20 | |
21 # includes and libs | |
22 -INCS = -I. -I/usr/include | |
23 -LIBS = -L/usr/lib -lc -lX11 | |
24 +INCS = -I. -I/usr/include -I/usr/include/freetype2 | |
25 +LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft | |
26 | |
27 # flags | |
28 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE | |
29 diff --git a/tabbed.c b/tabbed.c | |
30 index d30206b..d08348c 100644 | |
31 --- a/tabbed.c | |
32 +++ b/tabbed.c | |
33 @@ -15,6 +15,7 @@ | |
34 #include <X11/Xproto.h> | |
35 #include <X11/Xutil.h> | |
36 #include <X11/XKBlib.h> | |
37 +#include <X11/Xft/Xft.h> | |
38 | |
39 #include "arg.h" | |
40 | |
41 @@ -64,16 +65,15 @@ typedef struct { | |
42 | |
43 typedef struct { | |
44 int x, y, w, h; | |
45 - unsigned long norm[ColLast]; | |
46 - unsigned long sel[ColLast]; | |
47 + XftColor norm[ColLast]; | |
48 + XftColor sel[ColLast]; | |
49 Drawable drawable; | |
50 GC gc; | |
51 struct { | |
52 int ascent; | |
53 int descent; | |
54 int height; | |
55 - XFontSet set; | |
56 - XFontStruct *xfont; | |
57 + XftFont *xfont; | |
58 } font; | |
59 } DC; /* draw context */ | |
60 | |
61 @@ -95,7 +95,7 @@ static void createnotify(const XEvent *e); | |
62 static void destroynotify(const XEvent *e); | |
63 static void die(const char *errstr, ...); | |
64 static void drawbar(void); | |
65 -static void drawtext(const char *text, unsigned long col[ColLast]); | |
66 +static void drawtext(const char *text, XftColor col[ColLast]); | |
67 static void *emallocz(size_t size); | |
68 static void *erealloc(void *o, size_t size); | |
69 static void expose(const XEvent *e); | |
70 @@ -105,7 +105,7 @@ static void focusonce(const Arg *arg); | |
71 static void fullscreen(const Arg *arg); | |
72 static char* getatom(int a); | |
73 static int getclient(Window w); | |
74 -static unsigned long getcolor(const char *colstr); | |
75 +static XftColor getcolor(const char *colstr); | |
76 static int getfirsttab(void); | |
77 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int s… | |
78 static void initfont(const char *fontstr); | |
79 @@ -219,12 +219,6 @@ cleanup(void) { | |
80 free(clients); | |
81 clients = NULL; | |
82 | |
83 - if(dc.font.set) { | |
84 - XFreeFontSet(dpy, dc.font.set); | |
85 - } else { | |
86 - XFreeFont(dpy, dc.font.xfont); | |
87 - } | |
88 - | |
89 XFreePixmap(dpy, dc.drawable); | |
90 XFreeGC(dpy, dc.gc); | |
91 XDestroyWindow(dpy, win); | |
92 @@ -305,7 +299,7 @@ die(const char *errstr, ...) { | |
93 | |
94 void | |
95 drawbar(void) { | |
96 - unsigned long *col; | |
97 + XftColor *col; | |
98 int c, fc, width, n = 0; | |
99 char *name = NULL; | |
100 | |
101 @@ -362,12 +356,13 @@ drawbar(void) { | |
102 } | |
103 | |
104 void | |
105 -drawtext(const char *text, unsigned long col[ColLast]) { | |
106 +drawtext(const char *text, XftColor col[ColLast]) { | |
107 int i, x, y, h, len, olen; | |
108 char buf[256]; | |
109 + XftDraw *d; | |
110 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | |
111 | |
112 - XSetForeground(dpy, dc.gc, col[ColBG]); | |
113 + XSetForeground(dpy, dc.gc, col[ColBG].pixel); | |
114 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | |
115 if(!text) | |
116 return; | |
117 @@ -388,13 +383,10 @@ drawtext(const char *text, unsigned long col[ColLa… | |
118 for(i = len; i && i > len - 3; buf[--i] = '.'); | |
119 } | |
120 | |
121 - XSetForeground(dpy, dc.gc, col[ColFG]); | |
122 - if(dc.font.set) { | |
123 - XmbDrawString(dpy, dc.drawable, dc.font.set, | |
124 - dc.gc, x, y, buf, len); | |
125 - } else { | |
126 - XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); | |
127 - } | |
128 + d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen),… | |
129 + | |
130 + XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar… | |
131 + XftDrawDestroy(d); | |
132 } | |
133 | |
134 void * | |
135 @@ -524,15 +516,14 @@ getclient(Window w) { | |
136 return -1; | |
137 } | |
138 | |
139 -unsigned long | |
140 +XftColor | |
141 getcolor(const char *colstr) { | |
142 - Colormap cmap = DefaultColormap(dpy, screen); | |
143 - XColor color; | |
144 + XftColor color; | |
145 | |
146 - if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) | |
147 + if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultC… | |
148 die("tabbed: cannot allocate color '%s'\n", colstr); | |
149 | |
150 - return color.pixel; | |
151 + return color; | |
152 } | |
153 | |
154 int | |
155 @@ -585,41 +576,12 @@ gettextprop(Window w, Atom atom, char *text, unsig… | |
156 | |
157 void | |
158 initfont(const char *fontstr) { | |
159 - char *def, **missing, **font_names; | |
160 - int i, n; | |
161 - XFontStruct **xfonts; | |
162 - | |
163 - missing = NULL; | |
164 - if(dc.font.set) | |
165 - XFreeFontSet(dpy, dc.font.set); | |
166 - | |
167 - dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | |
168 - if(missing) { | |
169 - while(n--) | |
170 - fprintf(stderr, "tabbed: missing fontset: %s\n"… | |
171 - XFreeStringList(missing); | |
172 - } | |
173 + if(!(dc.font.xfont = XftFontOpenName(dpy, screen, fontstr)) | |
174 + && !(dc.font.xfont = XftFontOpenName(dpy, screen, "fixed"))) | |
175 + die("error, cannot load font: '%s'\n", fontstr); | |
176 | |
177 - if(dc.font.set) { | |
178 - dc.font.ascent = dc.font.descent = 0; | |
179 - n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | |
180 - for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i <… | |
181 - dc.font.ascent = MAX(dc.font.ascent, (*xfonts)-… | |
182 - dc.font.descent = MAX(dc.font.descent,(*xfonts)… | |
183 - xfonts++; | |
184 - } | |
185 - } else { | |
186 - if(dc.font.xfont) | |
187 - XFreeFont(dpy, dc.font.xfont); | |
188 - dc.font.xfont = NULL; | |
189 - if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) | |
190 - && !(dc.font.xfont = XLoadQueryFont(dpy… | |
191 - die("tabbed: cannot load font: '%s'\n", fontstr… | |
192 - } | |
193 - | |
194 - dc.font.ascent = dc.font.xfont->ascent; | |
195 - dc.font.descent = dc.font.xfont->descent; | |
196 - } | |
197 + dc.font.ascent = dc.font.xfont->ascent; | |
198 + dc.font.descent = dc.font.xfont->descent; | |
199 dc.font.height = dc.font.ascent + dc.font.descent; | |
200 } | |
201 | |
202 @@ -972,11 +934,9 @@ setup(void) { | |
203 dc.drawable = XCreatePixmap(dpy, root, ww, wh, | |
204 DefaultDepth(dpy, screen)); | |
205 dc.gc = XCreateGC(dpy, root, 0, 0); | |
206 - if(!dc.font.set) | |
207 - XSetFont(dpy, dc.gc, dc.font.xfont->fid); | |
208 | |
209 win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0, | |
210 - dc.norm[ColFG], dc.norm[ColBG]); | |
211 + dc.norm[ColFG].pixel, dc.norm[ColBG].pixel); | |
212 XMapRaised(dpy, win); | |
213 XSelectInput(dpy, win, SubstructureNotifyMask|FocusChangeMask| | |
214 ButtonPressMask|ExposureMask|KeyPressMask|Prope… | |
215 @@ -1040,15 +1000,9 @@ spawn(const Arg *arg) { | |
216 | |
217 int | |
218 textnw(const char *text, unsigned int len) { | |
219 - XRectangle r; | |
220 - | |
221 - if(dc.font.set) { | |
222 - XmbTextExtents(dc.font.set, text, len, NULL, &r); | |
223 - | |
224 - return r.width; | |
225 - } | |
226 - | |
227 - return XTextWidth(dc.font.xfont, text, len); | |
228 + XGlyphInfo ext; | |
229 + XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, … | |
230 + return ext.xOff; | |
231 } | |
232 | |
233 void |