aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2012-11-11 19:38:41 +0100
committerChristoph Lohmann <20h@r-36.net>2012-11-11 19:38:41 +0100
commitc4a9ccec19b14a6bdc980d149e2c27c30f250945 (patch)
tree23ae7c936c249d0b19e28677127f3e23b672ba03 /st.c
parent5d5a7c627a3709c3758c516de87609bb6b518e13 (diff)
downloadst-c4a9ccec19b14a6bdc980d149e2c27c30f250945.tar.gz
st-c4a9ccec19b14a6bdc980d149e2c27c30f250945.zip
Removing some xft naming cruft.
Diffstat (limited to 'st.c')
-rw-r--r--st.c82
1 files changed, 43 insertions, 39 deletions
diff --git a/st.c b/st.c
index 2919082..c043e3f 100644
--- a/st.c
+++ b/st.c
@@ -28,8 +28,12 @@
28#include <X11/extensions/Xdbe.h> 28#include <X11/extensions/Xdbe.h>
29#include <X11/Xft/Xft.h> 29#include <X11/Xft/Xft.h>
30#include <fontconfig/fontconfig.h> 30#include <fontconfig/fontconfig.h>
31
31#define Glyph Glyph_ 32#define Glyph Glyph_
32#define Font Font_ 33#define Font Font_
34#define Draw XftDraw *
35#define Colour XftColor
36#define Colourmap Colormap
33 37
34#if defined(__linux) 38#if defined(__linux)
35 #include <pty.h> 39 #include <pty.h>
@@ -198,14 +202,14 @@ typedef struct {
198 202
199/* Purely graphic info */ 203/* Purely graphic info */
200typedef struct { 204typedef struct {
201 Display* dpy; 205 Display *dpy;
202 Colormap cmap; 206 Colourmap cmap;
203 Window win; 207 Window win;
204 XdbeBackBuffer buf; 208 XdbeBackBuffer buf;
205 Atom xembed, wmdeletewin; 209 Atom xembed, wmdeletewin;
206 XIM xim; 210 XIM xim;
207 XIC xic; 211 XIC xic;
208 XftDraw *xft_draw; 212 Draw draw;
209 Visual *vis; 213 Visual *vis;
210 int scr; 214 int scr;
211 bool isfixed; /* is fixed geometry? */ 215 bool isfixed; /* is fixed geometry? */
@@ -267,12 +271,12 @@ typedef struct {
267 int descent; 271 int descent;
268 short lbearing; 272 short lbearing;
269 short rbearing; 273 short rbearing;
270 XftFont *xft_set; 274 XftFont *set;
271} Font; 275} Font;
272 276
273/* Drawing Context */ 277/* Drawing Context */
274typedef struct { 278typedef struct {
275 XftColor xft_col[LEN(colorname) < 256 ? 256 : LEN(colorname)]; 279 Colour col[LEN(colorname) < 256 ? 256 : LEN(colorname)];
276 GC gc; 280 GC gc;
277 Font font, bfont, ifont, ibfont; 281 Font font, bfont, ifont, ibfont;
278} DC; 282} DC;
@@ -2151,19 +2155,19 @@ xresize(int col, int row) {
2151 xw.tw = MAX(1, 2*borderpx + col * xw.cw); 2155 xw.tw = MAX(1, 2*borderpx + col * xw.cw);
2152 xw.th = MAX(1, 2*borderpx + row * xw.ch); 2156 xw.th = MAX(1, 2*borderpx + row * xw.ch);
2153 2157
2154 XftDrawChange(xw.xft_draw, xw.buf); 2158 XftDrawChange(xw.draw, xw.buf);
2155} 2159}
2156 2160
2157void 2161void
2158xloadcols(void) { 2162xloadcols(void) {
2159 int i, r, g, b; 2163 int i, r, g, b;
2160 XRenderColor xft_color = { .alpha = 0 }; 2164 XRenderColor color = { .alpha = 0 };
2161 2165
2162 /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */ 2166 /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */
2163 for(i = 0; i < LEN(colorname); i++) { 2167 for(i = 0; i < LEN(colorname); i++) {
2164 if(!colorname[i]) 2168 if(!colorname[i])
2165 continue; 2169 continue;
2166 if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], &dc.xft_col[i])) { 2170 if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], &dc.col[i])) {
2167 die("Could not allocate color '%s'\n", colorname[i]); 2171 die("Could not allocate color '%s'\n", colorname[i]);
2168 } 2172 }
2169 } 2173 }
@@ -2172,10 +2176,10 @@ xloadcols(void) {
2172 for(i = 16, r = 0; r < 6; r++) { 2176 for(i = 16, r = 0; r < 6; r++) {
2173 for(g = 0; g < 6; g++) { 2177 for(g = 0; g < 6; g++) {
2174 for(b = 0; b < 6; b++) { 2178 for(b = 0; b < 6; b++) {
2175 xft_color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r; 2179 color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
2176 xft_color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; 2180 color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
2177 xft_color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; 2181 color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
2178 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, &dc.xft_col[i])) { 2182 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) {
2179 die("Could not allocate color %d\n", i); 2183 die("Could not allocate color %d\n", i);
2180 } 2184 }
2181 i++; 2185 i++;
@@ -2184,9 +2188,9 @@ xloadcols(void) {
2184 } 2188 }
2185 2189
2186 for(r = 0; r < 24; r++, i++) { 2190 for(r = 0; r < 24; r++, i++) {
2187 xft_color.red = xft_color.green = xft_color.blue = 0x0808 + 0x0a0a * r; 2191 color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
2188 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, 2192 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color,
2189 &dc.xft_col[i])) { 2193 &dc.col[i])) {
2190 die("Could not allocate color %d\n", i); 2194 die("Could not allocate color %d\n", i);
2191 } 2195 }
2192 } 2196 }
@@ -2194,8 +2198,8 @@ xloadcols(void) {
2194 2198
2195void 2199void
2196xtermclear(int col1, int row1, int col2, int row2) { 2200xtermclear(int col1, int row1, int col2, int row2) {
2197 XftDrawRect(xw.xft_draw, 2201 XftDrawRect(xw.draw,
2198 &dc.xft_col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg], 2202 &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
2199 borderpx + col1 * xw.cw, 2203 borderpx + col1 * xw.cw,
2200 borderpx + row1 * xw.ch, 2204 borderpx + row1 * xw.ch,
2201 (col2-col1+1) * xw.cw, 2205 (col2-col1+1) * xw.cw,
@@ -2207,8 +2211,8 @@ xtermclear(int col1, int row1, int col2, int row2) {
2207 */ 2211 */
2208void 2212void
2209xclear(int x1, int y1, int x2, int y2) { 2213xclear(int x1, int y1, int x2, int y2) {
2210 XftDrawRect(xw.xft_draw, 2214 XftDrawRect(xw.draw,
2211 &dc.xft_col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg], 2215 &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
2212 x1, y1, x2-x1, y2-y1); 2216 x1, y1, x2-x1, y2-y1);
2213} 2217}
2214 2218
@@ -2245,17 +2249,17 @@ xloadfont(Font *f, FcPattern *pattern) {
2245 match = XftFontMatch(xw.dpy, xw.scr, pattern, &result); 2249 match = XftFontMatch(xw.dpy, xw.scr, pattern, &result);
2246 if(!match) 2250 if(!match)
2247 return 1; 2251 return 1;
2248 if(!(f->xft_set = XftFontOpenPattern(xw.dpy, match))) { 2252 if(!(f->set = XftFontOpenPattern(xw.dpy, match))) {
2249 FcPatternDestroy(match); 2253 FcPatternDestroy(match);
2250 return 1; 2254 return 1;
2251 } 2255 }
2252 2256
2253 f->ascent = f->xft_set->ascent; 2257 f->ascent = f->set->ascent;
2254 f->descent = f->xft_set->descent; 2258 f->descent = f->set->descent;
2255 f->lbearing = 0; 2259 f->lbearing = 0;
2256 f->rbearing = f->xft_set->max_advance_width; 2260 f->rbearing = f->set->max_advance_width;
2257 2261
2258 f->height = f->xft_set->height; 2262 f->height = f->set->height;
2259 f->width = f->lbearing + f->rbearing; 2263 f->width = f->lbearing + f->rbearing;
2260 2264
2261 return 0; 2265 return 0;
@@ -2365,8 +2369,8 @@ xinit(void) {
2365 xw.fy = 0; 2369 xw.fy = 0;
2366 } 2370 }
2367 2371
2368 attrs.background_pixel = dc.xft_col[defaultbg].pixel; 2372 attrs.background_pixel = dc.col[defaultbg].pixel;
2369 attrs.border_pixel = dc.xft_col[defaultbg].pixel; 2373 attrs.border_pixel = dc.col[defaultbg].pixel;
2370 attrs.bit_gravity = NorthWestGravity; 2374 attrs.bit_gravity = NorthWestGravity;
2371 attrs.event_mask = FocusChangeMask | KeyPressMask 2375 attrs.event_mask = FocusChangeMask | KeyPressMask
2372 | ExposureMask | VisibilityChangeMask | StructureNotifyMask 2376 | ExposureMask | VisibilityChangeMask | StructureNotifyMask
@@ -2387,7 +2391,7 @@ xinit(void) {
2387 xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied); 2391 xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied);
2388 2392
2389 /* Xft rendering context */ 2393 /* Xft rendering context */
2390 xw.xft_draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); 2394 xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
2391 2395
2392 /* input methods */ 2396 /* input methods */
2393 xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL); 2397 xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
@@ -2420,20 +2424,20 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2420 width = charlen * xw.cw; 2424 width = charlen * xw.cw;
2421 Font *font = &dc.font; 2425 Font *font = &dc.font;
2422 XGlyphInfo extents; 2426 XGlyphInfo extents;
2423 XftColor *fg = &dc.xft_col[base.fg], *bg = &dc.xft_col[base.bg], 2427 Colour *fg = &dc.col[base.fg], *bg = &dc.col[base.bg],
2424 *temp, revfg, revbg; 2428 *temp, revfg, revbg;
2425 XRenderColor colfg, colbg; 2429 XRenderColor colfg, colbg;
2426 2430
2427 if(base.mode & ATTR_BOLD) { 2431 if(base.mode & ATTR_BOLD) {
2428 if(BETWEEN(base.fg, 0, 7)) { 2432 if(BETWEEN(base.fg, 0, 7)) {
2429 /* basic system colors */ 2433 /* basic system colors */
2430 fg = &dc.xft_col[base.fg + 8]; 2434 fg = &dc.col[base.fg + 8];
2431 } else if(BETWEEN(base.fg, 16, 195)) { 2435 } else if(BETWEEN(base.fg, 16, 195)) {
2432 /* 256 colors */ 2436 /* 256 colors */
2433 fg = &dc.xft_col[base.fg + 36]; 2437 fg = &dc.col[base.fg + 36];
2434 } else if(BETWEEN(base.fg, 232, 251)) { 2438 } else if(BETWEEN(base.fg, 232, 251)) {
2435 /* greyscale */ 2439 /* greyscale */
2436 fg = &dc.xft_col[base.fg + 4]; 2440 fg = &dc.col[base.fg + 4];
2437 } 2441 }
2438 /* 2442 /*
2439 * Those ranges will not be brightened: 2443 * Those ranges will not be brightened:
@@ -2450,8 +2454,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2450 font = &dc.ibfont; 2454 font = &dc.ibfont;
2451 2455
2452 if(IS_SET(MODE_REVERSE)) { 2456 if(IS_SET(MODE_REVERSE)) {
2453 if(fg == &dc.xft_col[defaultfg]) { 2457 if(fg == &dc.col[defaultfg]) {
2454 fg = &dc.xft_col[defaultbg]; 2458 fg = &dc.col[defaultbg];
2455 } else { 2459 } else {
2456 colfg.red = ~fg->color.red; 2460 colfg.red = ~fg->color.red;
2457 colfg.green = ~fg->color.green; 2461 colfg.green = ~fg->color.green;
@@ -2461,8 +2465,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2461 fg = &revfg; 2465 fg = &revfg;
2462 } 2466 }
2463 2467
2464 if(bg == &dc.xft_col[defaultbg]) { 2468 if(bg == &dc.col[defaultbg]) {
2465 bg = &dc.xft_col[defaultfg]; 2469 bg = &dc.col[defaultfg];
2466 } else { 2470 } else {
2467 colbg.red = ~bg->color.red; 2471 colbg.red = ~bg->color.red;
2468 colbg.green = ~bg->color.green; 2472 colbg.green = ~bg->color.green;
@@ -2476,7 +2480,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2476 if(base.mode & ATTR_REVERSE) 2480 if(base.mode & ATTR_REVERSE)
2477 temp = fg, fg = bg, bg = temp; 2481 temp = fg, fg = bg, bg = temp;
2478 2482
2479 XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen, 2483 XftTextExtentsUtf8(xw.dpy, font->set, (FcChar8 *)s, bytelen,
2480 &extents); 2484 &extents);
2481 width = extents.xOff; 2485 width = extents.xOff;
2482 2486
@@ -2494,12 +2498,12 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2494 if(y == term.row-1) 2498 if(y == term.row-1)
2495 xclear(winx, winy + xw.ch, winx + width, xw.h); 2499 xclear(winx, winy + xw.ch, winx + width, xw.h);
2496 2500
2497 XftDrawRect(xw.xft_draw, bg, winx, winy, width, xw.ch); 2501 XftDrawRect(xw.draw, bg, winx, winy, width, xw.ch);
2498 XftDrawStringUtf8(xw.xft_draw, fg, font->xft_set, winx, 2502 XftDrawStringUtf8(xw.draw, fg, font->set, winx,
2499 winy + font->ascent, (FcChar8 *)s, bytelen); 2503 winy + font->ascent, (FcChar8 *)s, bytelen);
2500 2504
2501 if(base.mode & ATTR_UNDERLINE) { 2505 if(base.mode & ATTR_UNDERLINE) {
2502 XftDrawRect(xw.xft_draw, fg, winx, winy + font->ascent + 1, 2506 XftDrawRect(xw.draw, fg, winx, winy + font->ascent + 1,
2503 width, 1); 2507 width, 1);
2504 } 2508 }
2505} 2509}