| 9 |
9 |
|
#include "util.h" |
| 10 |
10 |
|
|
| 11 |
11 |
|
#define UTF_INVALID 0xFFFD |
| 12 |
|
- |
#define UTF_SIZ 4 |
|
12 |
+ |
#define UTF_SIZ 4 |
| 13 |
13 |
|
|
| 14 |
14 |
|
static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; |
| 15 |
15 |
|
static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; |
|
| 17 |
17 |
|
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; |
| 18 |
18 |
|
|
| 19 |
19 |
|
static long |
| 20 |
|
- |
utf8decodebyte(const char c, size_t *i) { |
| 21 |
|
- |
for(*i = 0; *i < (UTF_SIZ + 1); ++(*i)) |
| 22 |
|
- |
if(((unsigned char)c & utfmask[*i]) == utfbyte[*i]) |
|
20 |
+ |
utf8decodebyte(const char c, size_t *i) |
|
21 |
+ |
{ |
|
22 |
+ |
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) |
|
23 |
+ |
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) |
| 23 |
24 |
|
return (unsigned char)c & ~utfmask[*i]; |
| 24 |
25 |
|
return 0; |
| 25 |
26 |
|
} |
| 26 |
27 |
|
|
| 27 |
28 |
|
static size_t |
| 28 |
|
- |
utf8validate(long *u, size_t i) { |
| 29 |
|
- |
if(!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) |
|
29 |
+ |
utf8validate(long *u, size_t i) |
|
30 |
+ |
{ |
|
31 |
+ |
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) |
| 30 |
32 |
|
*u = UTF_INVALID; |
| 31 |
|
- |
for(i = 1; *u > utfmax[i]; ++i) |
|
33 |
+ |
for (i = 1; *u > utfmax[i]; ++i) |
| 32 |
34 |
|
; |
| 33 |
35 |
|
return i; |
| 34 |
36 |
|
} |
| 35 |
37 |
|
|
| 36 |
38 |
|
static size_t |
| 37 |
|
- |
utf8decode(const char *c, long *u, size_t clen) { |
|
39 |
+ |
utf8decode(const char *c, long *u, size_t clen) |
|
40 |
+ |
{ |
| 38 |
41 |
|
size_t i, j, len, type; |
| 39 |
42 |
|
long udecoded; |
| 40 |
43 |
|
|
| 41 |
44 |
|
*u = UTF_INVALID; |
| 42 |
|
- |
if(!clen) |
|
45 |
+ |
if (!clen) |
| 43 |
46 |
|
return 0; |
| 44 |
47 |
|
udecoded = utf8decodebyte(c[0], &len); |
| 45 |
|
- |
if(!BETWEEN(len, 1, UTF_SIZ)) |
|
48 |
+ |
if (!BETWEEN(len, 1, UTF_SIZ)) |
| 46 |
49 |
|
return 1; |
| 47 |
|
- |
for(i = 1, j = 1; i < clen && j < len; ++i, ++j) { |
|
50 |
+ |
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { |
| 48 |
51 |
|
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); |
| 49 |
|
- |
if(type != 0) |
|
52 |
+ |
if (type) |
| 50 |
53 |
|
return j; |
| 51 |
54 |
|
} |
| 52 |
|
- |
if(j < len) |
|
55 |
+ |
if (j < len) |
| 53 |
56 |
|
return 0; |
| 54 |
57 |
|
*u = udecoded; |
| 55 |
58 |
|
utf8validate(u, len); |
|
59 |
+ |
|
| 56 |
60 |
|
return len; |
| 57 |
61 |
|
} |
| 58 |
62 |
|
|
| 59 |
63 |
|
Drw * |
| 60 |
|
- |
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) { |
| 61 |
|
- |
Drw *drw = (Drw *)calloc(1, sizeof(Drw)); |
| 62 |
|
- |
if(!drw) |
| 63 |
|
- |
return NULL; |
|
64 |
+ |
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) |
|
65 |
+ |
{ |
|
66 |
+ |
Drw *drw; |
|
67 |
+ |
|
|
68 |
+ |
drw = ecalloc(1, sizeof(Drw)); |
| 64 |
69 |
|
drw->dpy = dpy; |
| 65 |
70 |
|
drw->screen = screen; |
| 66 |
71 |
|
drw->root = root; |
|
| 70 |
75 |
|
drw->gc = XCreateGC(dpy, root, 0, NULL); |
| 71 |
76 |
|
drw->fontcount = 0; |
| 72 |
77 |
|
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); |
|
78 |
+ |
|
| 73 |
79 |
|
return drw; |
| 74 |
80 |
|
} |
| 75 |
81 |
|
|
| 76 |
82 |
|
void |
| 77 |
|
- |
drw_resize(Drw *drw, unsigned int w, unsigned int h) { |
| 78 |
|
- |
if(!drw) |
| 79 |
|
- |
return; |
|
83 |
+ |
drw_resize(Drw *drw, unsigned int w, unsigned int h) |
|
84 |
+ |
{ |
| 80 |
85 |
|
drw->w = w; |
| 81 |
86 |
|
drw->h = h; |
| 82 |
|
- |
if(drw->drawable != 0) |
|
87 |
+ |
if (drw->drawable) |
| 83 |
88 |
|
XFreePixmap(drw->dpy, drw->drawable); |
| 84 |
89 |
|
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); |
| 85 |
90 |
|
} |
| 86 |
91 |
|
|
| 87 |
92 |
|
void |
| 88 |
|
- |
drw_free(Drw *drw) { |
|
93 |
+ |
drw_free(Drw *drw) |
|
94 |
+ |
{ |
| 89 |
95 |
|
size_t i; |
| 90 |
|
- |
for (i = 0; i < drw->fontcount; i++) { |
|
96 |
+ |
|
|
97 |
+ |
for (i = 0; i < drw->fontcount; i++) |
| 91 |
98 |
|
drw_font_free(drw->fonts[i]); |
| 92 |
|
- |
} |
| 93 |
99 |
|
XFreePixmap(drw->dpy, drw->drawable); |
| 94 |
100 |
|
XFreeGC(drw->dpy, drw->gc); |
| 95 |
101 |
|
free(drw); |
|
| 99 |
105 |
|
* drw_font_create instead. |
| 100 |
106 |
|
*/ |
| 101 |
107 |
|
static Fnt * |
| 102 |
|
- |
drw_font_xcreate(Drw *drw, const char *fontname, FcPattern *fontpattern) { |
|
108 |
+ |
drw_font_xcreate(Drw *drw, const char *fontname, FcPattern *fontpattern) |
|
109 |
+ |
{ |
| 103 |
110 |
|
Fnt *font; |
| 104 |
|
- |
|
| 105 |
|
- |
if (!(fontname || fontpattern)) |
| 106 |
|
- |
die("No font specified.\n"); |
| 107 |
|
- |
|
| 108 |
|
- |
if (!(font = (Fnt *)calloc(1, sizeof(Fnt)))) |
| 109 |
|
- |
return NULL; |
|
111 |
+ |
XftFont *xfont = NULL; |
|
112 |
+ |
FcPattern *pattern = NULL; |
| 110 |
113 |
|
|
| 111 |
114 |
|
if (fontname) { |
| 112 |
115 |
|
/* Using the pattern found at font->xfont->pattern does not yield same |
|
| 115 |
118 |
|
* behaviour whereas the former just results in |
| 116 |
119 |
|
* missing-character-rectangles being drawn, at least with some fonts. |
| 117 |
120 |
|
*/ |
| 118 |
|
- |
if (!(font->xfont = XftFontOpenName(drw->dpy, drw->screen, fontname)) || |
| 119 |
|
- |
!(font->pattern = FcNameParse((FcChar8 *) fontname))) { |
| 120 |
|
- |
if (font->xfont) { |
| 121 |
|
- |
XftFontClose(drw->dpy, font->xfont); |
| 122 |
|
- |
font->xfont = NULL; |
| 123 |
|
- |
} |
|
121 |
+ |
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { |
| 124 |
122 |
|
fprintf(stderr, "error, cannot load font: '%s'\n", fontname); |
|
123 |
+ |
return NULL; |
|
124 |
+ |
} |
|
125 |
+ |
if (!(pattern = FcNameParse((FcChar8 *) fontname))) { |
|
126 |
+ |
fprintf(stderr, "error, cannot load font: '%s'\n", fontname); |
|
127 |
+ |
XftFontClose(drw->dpy, xfont); |
|
128 |
+ |
return NULL; |
| 125 |
129 |
|
} |
| 126 |
130 |
|
} else if (fontpattern) { |
| 127 |
|
- |
if (!(font->xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { |
|
131 |
+ |
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { |
| 128 |
132 |
|
fprintf(stderr, "error, cannot load font pattern.\n"); |
| 129 |
|
- |
} else { |
| 130 |
|
- |
font->pattern = NULL; |
|
133 |
+ |
return NULL; |
| 131 |
134 |
|
} |
|
135 |
+ |
} else { |
|
136 |
+ |
die("no font specified.\n"); |
| 132 |
137 |
|
} |
| 133 |
138 |
|
|
| 134 |
|
- |
if (!font->xfont) { |
| 135 |
|
- |
free(font); |
| 136 |
|
- |
return NULL; |
| 137 |
|
- |
} |
| 138 |
|
- |
|
| 139 |
|
- |
font->ascent = font->xfont->ascent; |
| 140 |
|
- |
font->descent = font->xfont->descent; |
|
139 |
+ |
font = ecalloc(1, sizeof(Fnt)); |
|
140 |
+ |
font->xfont = xfont; |
|
141 |
+ |
font->pattern = pattern; |
|
142 |
+ |
font->ascent = xfont->ascent; |
|
143 |
+ |
font->descent = xfont->descent; |
| 141 |
144 |
|
font->h = font->ascent + font->descent; |
| 142 |
145 |
|
font->dpy = drw->dpy; |
|
146 |
+ |
|
| 143 |
147 |
|
return font; |
| 144 |
148 |
|
} |
| 145 |
149 |
|
|
| 146 |
150 |
|
Fnt* |
| 147 |
|
- |
drw_font_create(Drw *drw, const char *fontname) { |
|
151 |
+ |
drw_font_create(Drw *drw, const char *fontname) |
|
152 |
+ |
{ |
| 148 |
153 |
|
return drw_font_xcreate(drw, fontname, NULL); |
| 149 |
154 |
|
} |
| 150 |
155 |
|
|
| 151 |
156 |
|
void |
| 152 |
|
- |
drw_load_fonts(Drw* drw, const char *fonts[], size_t fontcount) { |
|
157 |
+ |
drw_load_fonts(Drw* drw, const char *fonts[], size_t fontcount) |
|
158 |
+ |
{ |
| 153 |
159 |
|
size_t i; |
| 154 |
160 |
|
Fnt *font; |
|
161 |
+ |
|
| 155 |
162 |
|
for (i = 0; i < fontcount; i++) { |
| 156 |
163 |
|
if (drw->fontcount >= DRW_FONT_CACHE_SIZE) { |
| 157 |
|
- |
die("Font cache exhausted.\n"); |
|
164 |
+ |
die("font cache exhausted.\n"); |
| 158 |
165 |
|
} else if ((font = drw_font_xcreate(drw, fonts[i], NULL))) { |
| 159 |
166 |
|
drw->fonts[drw->fontcount++] = font; |
| 160 |
167 |
|
} |
|
| 162 |
169 |
|
} |
| 163 |
170 |
|
|
| 164 |
171 |
|
void |
| 165 |
|
- |
drw_font_free(Fnt *font) { |
| 166 |
|
- |
if(!font) |
|
172 |
+ |
drw_font_free(Fnt *font) |
|
173 |
+ |
{ |
|
174 |
+ |
if (!font) |
| 167 |
175 |
|
return; |
| 168 |
|
- |
if(font->pattern) |
|
176 |
+ |
if (font->pattern) |
| 169 |
177 |
|
FcPatternDestroy(font->pattern); |
| 170 |
178 |
|
XftFontClose(font->dpy, font->xfont); |
| 171 |
179 |
|
free(font); |
| 172 |
180 |
|
} |
| 173 |
181 |
|
|
| 174 |
182 |
|
Clr * |
| 175 |
|
- |
drw_clr_create(Drw *drw, const char *clrname) { |
|
183 |
+ |
drw_clr_create(Drw *drw, const char *clrname) |
|
184 |
+ |
{ |
| 176 |
185 |
|
Clr *clr; |
| 177 |
|
- |
Colormap cmap; |
| 178 |
|
- |
Visual *vis; |
| 179 |
186 |
|
|
| 180 |
|
- |
if(!drw) |
| 181 |
|
- |
return NULL; |
| 182 |
|
- |
clr = (Clr *)calloc(1, sizeof(Clr)); |
| 183 |
|
- |
if(!clr) |
| 184 |
|
- |
return NULL; |
| 185 |
|
- |
cmap = DefaultColormap(drw->dpy, drw->screen); |
| 186 |
|
- |
vis = DefaultVisual(drw->dpy, drw->screen); |
| 187 |
|
- |
if(!XftColorAllocName(drw->dpy, vis, cmap, clrname, &clr->rgb)) |
|
187 |
+ |
clr = ecalloc(1, sizeof(Clr)); |
|
188 |
+ |
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), |
|
189 |
+ |
DefaultColormap(drw->dpy, drw->screen), |
|
190 |
+ |
clrname, &clr->rgb)) |
| 188 |
191 |
|
die("error, cannot allocate color '%s'\n", clrname); |
| 189 |
192 |
|
clr->pix = clr->rgb.pixel; |
|
193 |
+ |
|
| 190 |
194 |
|
return clr; |
| 191 |
195 |
|
} |
| 192 |
196 |
|
|
| 193 |
197 |
|
void |
| 194 |
|
- |
drw_clr_free(Clr *clr) { |
| 195 |
|
- |
if(clr) |
| 196 |
|
- |
free(clr); |
|
198 |
+ |
drw_clr_free(Clr *clr) |
|
199 |
+ |
{ |
|
200 |
+ |
free(clr); |
| 197 |
201 |
|
} |
| 198 |
202 |
|
|
| 199 |
203 |
|
void |
| 200 |
|
- |
drw_setscheme(Drw *drw, ClrScheme *scheme) { |
| 201 |
|
- |
if(drw && scheme) |
| 202 |
|
- |
drw->scheme = scheme; |
|
204 |
+ |
drw_setscheme(Drw *drw, ClrScheme *scheme) |
|
205 |
+ |
{ |
|
206 |
+ |
drw->scheme = scheme; |
| 203 |
207 |
|
} |
| 204 |
208 |
|
|
| 205 |
209 |
|
void |
| 206 |
|
- |
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) { |
| 207 |
|
- |
int dx; |
| 208 |
|
- |
|
| 209 |
|
- |
if(!drw || !drw->fontcount || !drw->scheme) |
|
210 |
+ |
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) |
|
211 |
+ |
{ |
|
212 |
+ |
if (!drw->scheme) |
| 210 |
213 |
|
return; |
| 211 |
214 |
|
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->pix : drw->scheme->fg->pix); |
| 212 |
|
- |
dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4; |
| 213 |
|
- |
if(filled) |
| 214 |
|
- |
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1); |
| 215 |
|
- |
else if(empty) |
| 216 |
|
- |
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx, dx); |
|
215 |
+ |
if (filled) |
|
216 |
+ |
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w + 1, h + 1); |
|
217 |
+ |
else if (empty) |
|
218 |
+ |
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); |
| 217 |
219 |
|
} |
| 218 |
220 |
|
|
| 219 |
221 |
|
int |
| 220 |
|
- |
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) { |
|
222 |
+ |
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) |
|
223 |
+ |
{ |
| 221 |
224 |
|
char buf[1024]; |
| 222 |
225 |
|
int tx, ty, th; |
| 223 |
226 |
|
Extnts tex; |
| 224 |
|
- |
Colormap cmap; |
| 225 |
|
- |
Visual *vis; |
| 226 |
|
- |
XftDraw *d; |
|
227 |
+ |
XftDraw *d = NULL; |
| 227 |
228 |
|
Fnt *curfont, *nextfont; |
| 228 |
229 |
|
size_t i, len; |
| 229 |
230 |
|
int utf8strlen, utf8charlen, render; |
|
| 235 |
236 |
|
XftResult result; |
| 236 |
237 |
|
int charexists = 0; |
| 237 |
238 |
|
|
|
239 |
+ |
if (!drw->scheme || !drw->fontcount) |
|
240 |
+ |
return 0; |
|
241 |
+ |
|
| 238 |
242 |
|
if (!(render = x || y || w || h)) { |
| 239 |
243 |
|
w = ~w; |
| 240 |
|
- |
} |
| 241 |
|
- |
|
| 242 |
|
- |
if (!drw || !drw->scheme) { |
| 243 |
|
- |
return 0; |
| 244 |
|
- |
} else if (render) { |
| 245 |
|
- |
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->pix : drw->scheme->bg->pix); |
|
244 |
+ |
} else { |
|
245 |
+ |
XSetForeground(drw->dpy, drw->gc, invert ? |
|
246 |
+ |
drw->scheme->fg->pix : drw->scheme->bg->pix); |
| 246 |
247 |
|
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); |
| 247 |
|
- |
} |
| 248 |
|
- |
|
| 249 |
|
- |
if (!text || !drw->fontcount) { |
| 250 |
|
- |
return 0; |
| 251 |
|
- |
} else if (render) { |
| 252 |
|
- |
cmap = DefaultColormap(drw->dpy, drw->screen); |
| 253 |
|
- |
vis = DefaultVisual(drw->dpy, drw->screen); |
| 254 |
|
- |
d = XftDrawCreate(drw->dpy, drw->drawable, vis, cmap); |
|
248 |
+ |
d = XftDrawCreate(drw->dpy, drw->drawable, |
|
249 |
+ |
DefaultVisual(drw->dpy, drw->screen), |
|
250 |
+ |
DefaultColormap(drw->dpy, drw->screen)); |
| 255 |
251 |
|
} |
| 256 |
252 |
|
|
| 257 |
253 |
|
curfont = drw->fonts[0]; |
|
| 274 |
270 |
|
} |
| 275 |
271 |
|
} |
| 276 |
272 |
|
|
| 277 |
|
- |
if (!charexists || (nextfont && nextfont != curfont)) { |
|
273 |
+ |
if (!charexists || (nextfont && nextfont != curfont)) |
| 278 |
274 |
|
break; |
| 279 |
|
- |
} else { |
|
275 |
+ |
else |
| 280 |
276 |
|
charexists = 0; |
| 281 |
|
- |
} |
| 282 |
277 |
|
} |
| 283 |
278 |
|
|
| 284 |
279 |
|
if (utf8strlen) { |
| 285 |
280 |
|
drw_font_getexts(curfont, utf8str, utf8strlen, &tex); |
| 286 |
281 |
|
/* shorten text if necessary */ |
| 287 |
|
- |
for(len = MIN(utf8strlen, (sizeof buf) - 1); len && (tex.w > w - drw->fonts[0]->h || w < drw->fonts[0]->h); len--) |
|
282 |
+ |
for (len = MIN(utf8strlen, (sizeof buf) - 1); len && (tex.w > w - drw->fonts[0]->h || w < drw->fonts[0]->h); len--) |
| 288 |
283 |
|
drw_font_getexts(curfont, utf8str, len, &tex); |
| 289 |
284 |
|
|
| 290 |
285 |
|
if (len) { |
| 291 |
286 |
|
memcpy(buf, utf8str, len); |
| 292 |
287 |
|
buf[len] = '\0'; |
| 293 |
|
- |
if(len < utf8strlen) |
| 294 |
|
- |
for(i = len; i && i > len - 3; buf[--i] = '.'); |
|
288 |
+ |
if (len < utf8strlen) |
|
289 |
+ |
for (i = len; i && i > len - 3; buf[--i] = '.'); |
| 295 |
290 |
|
|
| 296 |
291 |
|
if (render) { |
| 297 |
292 |
|
th = curfont->ascent + curfont->descent; |
|
| 299 |
294 |
|
tx = x + (h / 2); |
| 300 |
295 |
|
XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); |
| 301 |
296 |
|
} |
| 302 |
|
- |
|
| 303 |
297 |
|
x += tex.w; |
| 304 |
298 |
|
w -= tex.w; |
| 305 |
299 |
|
} |
|
| 316 |
310 |
|
*/ |
| 317 |
311 |
|
charexists = 1; |
| 318 |
312 |
|
|
| 319 |
|
- |
if (drw->fontcount >= DRW_FONT_CACHE_SIZE) { |
|
313 |
+ |
if (drw->fontcount >= DRW_FONT_CACHE_SIZE) |
| 320 |
314 |
|
continue; |
| 321 |
|
- |
} |
| 322 |
315 |
|
|
| 323 |
316 |
|
fccharset = FcCharSetCreate(); |
| 324 |
317 |
|
FcCharSetAddChar(fccharset, utf8codepoint); |
| 325 |
318 |
|
|
| 326 |
319 |
|
if (!drw->fonts[0]->pattern) { |
| 327 |
320 |
|
/* Refer to the comment in drw_font_xcreate for more |
| 328 |
|
- |
* information. |
| 329 |
|
- |
*/ |
| 330 |
|
- |
die("The first font in the cache must be loaded from a font string.\n"); |
|
321 |
+ |
* information. */ |
|
322 |
+ |
die("the first font in the cache must be loaded from a font string.\n"); |
| 331 |
323 |
|
} |
| 332 |
324 |
|
|
| 333 |
325 |
|
fcpattern = FcPatternDuplicate(drw->fonts[0]->pattern); |
|
| 346 |
338 |
|
if (curfont && XftCharExists(drw->dpy, curfont->xfont, utf8codepoint)) { |
| 347 |
339 |
|
drw->fonts[drw->fontcount++] = curfont; |
| 348 |
340 |
|
} else { |
| 349 |
|
- |
if (curfont) { |
| 350 |
|
- |
drw_font_free(curfont); |
| 351 |
|
- |
} |
|
341 |
+ |
drw_font_free(curfont); |
| 352 |
342 |
|
curfont = drw->fonts[0]; |
| 353 |
343 |
|
} |
| 354 |
344 |
|
} |
| 355 |
345 |
|
} |
| 356 |
346 |
|
} |
| 357 |
|
- |
|
| 358 |
|
- |
if (render) { |
|
347 |
+ |
if (d) |
| 359 |
348 |
|
XftDrawDestroy(d); |
| 360 |
|
- |
} |
| 361 |
349 |
|
|
| 362 |
350 |
|
return x; |
| 363 |
351 |
|
} |
| 364 |
352 |
|
|
| 365 |
353 |
|
void |
| 366 |
|
- |
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) { |
| 367 |
|
- |
if(!drw) |
| 368 |
|
- |
return; |
|
354 |
+ |
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) |
|
355 |
+ |
{ |
| 369 |
356 |
|
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); |
| 370 |
357 |
|
XSync(drw->dpy, False); |
| 371 |
358 |
|
} |
| 372 |
359 |
|
|
| 373 |
|
- |
|
| 374 |
360 |
|
void |
| 375 |
|
- |
drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) { |
|
361 |
+ |
drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) |
|
362 |
+ |
{ |
| 376 |
363 |
|
XGlyphInfo ext; |
| 377 |
364 |
|
|
| 378 |
|
- |
if(!font || !text) |
| 379 |
|
- |
return; |
| 380 |
365 |
|
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); |
| 381 |
366 |
|
tex->h = font->h; |
| 382 |
367 |
|
tex->w = ext.xOff; |
| 383 |
368 |
|
} |
| 384 |
369 |
|
|
| 385 |
370 |
|
unsigned int |
| 386 |
|
- |
drw_font_getexts_width(Fnt *font, const char *text, unsigned int len) { |
|
371 |
+ |
drw_font_getexts_width(Fnt *font, const char *text, unsigned int len) |
|
372 |
+ |
{ |
| 387 |
373 |
|
Extnts tex; |
| 388 |
374 |
|
|
| 389 |
|
- |
if(!font) |
| 390 |
|
- |
return -1; |
| 391 |
375 |
|
drw_font_getexts(font, text, len, &tex); |
|
376 |
+ |
|
| 392 |
377 |
|
return tex.w; |
| 393 |
378 |
|
} |
| 394 |
379 |
|
|
| 395 |
380 |
|
Cur * |
| 396 |
|
- |
drw_cur_create(Drw *drw, int shape) { |
| 397 |
|
- |
Cur *cur = (Cur *)calloc(1, sizeof(Cur)); |
|
381 |
+ |
drw_cur_create(Drw *drw, int shape) |
|
382 |
+ |
{ |
|
383 |
+ |
Cur *cur; |
| 398 |
384 |
|
|
| 399 |
|
- |
if(!drw || !cur) |
| 400 |
|
- |
return NULL; |
|
385 |
+ |
cur = ecalloc(1, sizeof(Cur)); |
| 401 |
386 |
|
cur->cursor = XCreateFontCursor(drw->dpy, shape); |
|
387 |
+ |
|
| 402 |
388 |
|
return cur; |
| 403 |
389 |
|
} |
| 404 |
390 |
|
|
| 405 |
391 |
|
void |
| 406 |
|
- |
drw_cur_free(Drw *drw, Cur *cursor) { |
| 407 |
|
- |
if(!drw || !cursor) |
|
392 |
+ |
drw_cur_free(Drw *drw, Cur *cursor) |
|
393 |
+ |
{ |
|
394 |
+ |
if (!cursor) |
| 408 |
395 |
|
return; |
| 409 |
396 |
|
XFreeCursor(drw->dpy, cursor->cursor); |
| 410 |
397 |
|
free(cursor); |