aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2009-02-11 02:32:08 +0000
committergotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2009-02-11 02:32:08 +0000
commitbb30ea30f049709336200cd9dffba9929c17f924 (patch)
tree829461b477dde4908431b7b99a94ba4776005f33
parent487a15633b9706bf44a18e7ff484e63c0311f347 (diff)
downloaddzen-bb30ea30f049709336200cd9dffba9929c17f924.tar.gz
dzen-bb30ea30f049709336200cd9dffba9929c17f924.zip
added XFT support
git-svn-id: http://dzen.googlecode.com/svn/trunk@241 f2baff5b-bf2c-0410-a398-912abdc3d8b2
-rw-r--r--config.mk34
-rw-r--r--draw.c102
-rw-r--r--dzen.h9
3 files changed, 136 insertions, 9 deletions
diff --git a/config.mk b/config.mk
index d54ea0c..ff82d69 100644
--- a/config.mk
+++ b/config.mk
@@ -18,22 +18,42 @@ INCS = -I. -I/usr/include -I${X11INC}
# Uncomment: Remove # from the beginning of respective lines
# Comment : Add # to the beginning of the respective lines
-# Option 1: No Xinerama no XPM
-LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
-CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\"
+## Option 1: No Xinerama no XPM no XFT
+#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
+#CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\"
-# Option 2: No Xinerama with XPM
+
+## Option 2: No Xinerama with XPM
#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXpm
#CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XPM
+
# Option 3: With Xinerama no XPM
#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama
#CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA
-# Option 4: With Xinerama and XPM
+
+## Option 4: With Xinerama and XPM
#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm
#CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM
+
+## Option 5: With XFT
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs xft`
+CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XFT `pkg-config --cflags xft`
+
+
+## Option 6: With XPM and XFT
+#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXpm `pkg-config --libs xft`
+#CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XPM -DDZEN_XFT `pkg-config --cflags xft`
+
+
+## Option 7: With Xinerama and XPM and XFT
+#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm `pkg-config --libs xft`
+#CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM -DDZEN_XFT `pkg-config --cflags xft`
+
+
+
# END of feature configuration
@@ -45,8 +65,8 @@ LDFLAGS = ${LIBS}
#CFLAGS += -xtarget=ultra
# Debugging
-#CFLAGS = ${INCS} -DVERSION=\"${VERSION}\" -std=gnu89 -pedantic -Wall -W -Wno-missing-field-initializers -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -O2 -pipe -DDZEN_XPM
-#LDFLAGS = -g ${LIBS}
+#CFLAGS = ${INCS} -DVERSION=\"${VERSION}\" -std=gnu89 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -O2 -pipe -DDZEN_XFT `pkg-config --cflags xft`
+#LDFLAGS = ${LIBS}
# compiler and linker
CC = gcc
diff --git a/draw.c b/draw.c
index d627fa9..67880f9 100644
--- a/draw.c
+++ b/draw.c
@@ -63,6 +63,7 @@ int get_token(const char* line, int * t, char **tval);
static unsigned int
textnw(Fnt *font, const char *text, unsigned int len) {
+#ifndef DZEN_XFT
XRectangle r;
if(font->set) {
@@ -70,6 +71,12 @@ textnw(Fnt *font, const char *text, unsigned int len) {
return r.width;
}
return XTextWidth(font->xfont, text, len);
+#else
+ XftTextExtentsUtf8(dzen.dpy, dzen.font.xftfont, (unsigned const char *) text, strlen(text), dzen.font.extents);
+ if(dzen.font.extents->height > dzen.font.height)
+ dzen.font.height = dzen.font.extents->height;
+ return dzen.font.extents->width;
+#endif
}
@@ -102,6 +109,7 @@ getcolor(const char *colstr) {
void
setfont(const char *fontstr) {
+#ifndef DZEN_XFT
char *def, **missing;
int i, n;
@@ -138,6 +146,17 @@ setfont(const char *fontstr) {
dzen.font.descent = dzen.font.xfont->descent;
}
dzen.font.height = dzen.font.ascent + dzen.font.descent;
+#else
+ dzen.font.xftfont = XftFontOpenXlfd(dzen.dpy, dzen.screen, fontstr);
+ if(!dzen.font.xftfont)
+ dzen.font.xftfont = XftFontOpenName(dzen.dpy, dzen.screen, fontstr);
+ if(!dzen.font.xftfont)
+ fprintf(stderr, "error, cannot load font: '%s'\n", fontstr);
+ dzen.font.extents = malloc(sizeof(XGlyphInfo));
+ XftTextExtentsUtf8(dzen.dpy, dzen.font.xftfont, (unsigned const char *) fontstr, strlen(fontstr), dzen.font.extents);
+ dzen.font.height = dzen.font.xftfont->ascent + dzen.font.xftfont->descent;
+ dzen.font.width = (dzen.font.extents->width)/strlen(fontstr);
+#endif
}
@@ -326,6 +345,16 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
XpmColorSymbol xpms;
#endif
+#ifdef DZEN_XFT
+ XftDraw *xftd=NULL;
+ XftColor xftc;
+ char *xftcs;
+ int xftcs_f=0;
+
+ xftcs = dzen.fg;
+#endif
+
+
/* icon cache */
int ip;
@@ -355,6 +384,11 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
}
+#ifdef DZEN_XFT
+ xftd = XftDrawCreate(dzen.dpy, pm, DefaultVisual(dzen.dpy, dzen.screen),
+ DefaultColormap(dzen.dpy, dzen.screen));
+#endif
+
if(!reverse) {
XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]);
#ifdef DZEN_XPM
@@ -388,10 +422,12 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
xpma.valuemask = XpmColormap|XpmDepth|XpmVisual|XpmColorSymbols;
#endif
+#ifndef DZEN_XFT
if(!dzen.font.set){
gcv.font = dzen.font.xfont->fid;
XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
}
+#endif
cur_fnt = &dzen.font;
if( lnr != -1 && (lnr + dzen.slave_win.first_line_vis >= dzen.slave_win.tcnt)) {
@@ -580,10 +616,20 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case fg:
lastfg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColFG];
XSetForeground(dzen.dpy, dzen.tgc, lastfg);
+#ifdef DZEN_XFT
+ if(tval[0]) {
+ xftcs = estrdup(tval);
+ xftcs_f = 1;
+ } else {
+ xftcs = dzen.fg;
+ xftcs_f = 0;
+ }
+#endif
break;
case fn:
if(tval[0]) {
+#ifndef DZEN_XFT
if(!strncmp(tval, "dfnt", 4)) {
cur_fnt = &(dzen.fnpl[atoi(tval+4)]);
@@ -593,14 +639,19 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
}
}
else
+#endif
setfont(tval);
}
else {
cur_fnt = &dzen.font;
+#ifndef DZEN_XFT
if(!cur_fnt->set){
gcv.font = cur_fnt->xfont->fid;
XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
}
+#else
+ setfont(dzen.fnt ? dzen.fnt : FONT);
+#endif
}
py = set_posy ? py : (dzen.line_height - cur_fnt->height) / 2;
font_was_set = 1;
@@ -625,14 +676,28 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
lbuf[j - 3] = '.';
}
-
if(!nobg)
setcolor(&pm, px, tw, lastfg, lastbg, reverse, nobg);
+
+#ifndef DZEN_XFT
if(cur_fnt->set)
XmbDrawString(dzen.dpy, pm, cur_fnt->set,
dzen.tgc, px, py + cur_fnt->ascent, lbuf, strlen(lbuf));
else
XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
+#else
+ XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
+ DefaultColormap(dzen.dpy, dzen.screen), xftcs, &xftc);
+
+ XftDrawStringUtf8(xftd, &xftc,
+ cur_fnt->xftfont, px, py + dzen.font.xftfont->ascent, lbuf, strlen(lbuf));
+
+ if(xftcs_f) {
+ free(xftcs);
+ xftcs_f = 0;
+ }
+
+#endif
px += !pos_is_fixed ? tw : 0;
}
@@ -821,10 +886,20 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case fg:
lastfg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColFG];
XSetForeground(dzen.dpy, dzen.tgc, lastfg);
+#ifdef DZEN_XFT
+ if(tval[0]) {
+ xftcs = estrdup(tval);
+ xftcs_f = 1;
+ } else {
+ xftcs = dzen.fg;
+ xftcs_f = 0;
+ }
+#endif
break;
case fn:
if(tval[0]) {
+#ifndef DZEN_XFT
if(!strncmp(tval, "dfnt", 4)) {
cur_fnt = &(dzen.fnpl[atoi(tval+4)]);
@@ -834,14 +909,19 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
}
}
else
+#endif
setfont(tval);
}
else {
cur_fnt = &dzen.font;
+#ifndef DZEN_XFT
if(!cur_fnt->set){
gcv.font = cur_fnt->xfont->fid;
XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
}
+#else
+ setfont(dzen.fnt ? dzen.fnt : FONT);
+#endif
}
py = set_posy ? py : (dzen.line_height - cur_fnt->height) / 2;
font_was_set = 1;
@@ -866,14 +946,28 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
lbuf[j - 3] = '.';
}
-
if(!nobg)
setcolor(&pm, px, tw, lastfg, lastbg, reverse, nobg);
+
+#ifndef DZEN_XFT
if(cur_fnt->set)
XmbDrawString(dzen.dpy, pm, cur_fnt->set,
dzen.tgc, px, py + cur_fnt->ascent, lbuf, strlen(lbuf));
else
XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
+#else
+ XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
+ DefaultColormap(dzen.dpy, dzen.screen), xftcs, &xftc);
+
+ XftDrawStringUtf8(xftd, &xftc,
+ cur_fnt->xftfont, px, py + dzen.font.xftfont->ascent, lbuf, strlen(lbuf));
+
+ if(xftcs_f) {
+ free(xftcs);
+ xftcs_f = 0;
+ }
+
+#endif
px += !pos_is_fixed ? tw : 0;
/* expand/shrink dynamically */
@@ -927,6 +1021,10 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
XpmFreeAttributes(&xpma);
}
#endif
+
+#ifdef DZEN_XFT
+ XftDrawDestroy(xftd);
+#endif
}
return nodraw ? rbuf : NULL;
diff --git a/dzen.h b/dzen.h
index f31a629..9d17502 100644
--- a/dzen.h
+++ b/dzen.h
@@ -10,6 +10,9 @@
#ifdef DZEN_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
+#ifdef DZEN_XFT
+#include <X11/Xft/Xft.h>
+#endif
#define FONT "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*"
#define BGCOLOR "#111111"
@@ -48,8 +51,14 @@ struct Fnt {
int ascent;
int descent;
int height;
+#ifdef DZEN_XFT
+ XftFont *xftfont;
+ XGlyphInfo *extents;
+ int width;
+#endif
};
+
/* title window */
struct TW {
int x, y, width, height;