at v192 234 lines 6.6 kB view raw
1diff --git a/config.def.h b/config.def.h 2index b3da7f0..ce43686 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"; 14diff --git a/config.mk b/config.mk 15index dd741e4..ed3a2e9 100644 16--- a/config.mk 17+++ b/config.mk 18@@ -9,7 +9,7 @@ MANPREFIX = ${PREFIX}/share/man 19 20 # includes and libs 21 INCS = -I. -I/usr/include 22-LIBS = -L/usr/lib -lc -lX11 23+LIBS = -L/usr/lib -lc -lXft -lX11 24 25 # flags 26 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE 27diff --git a/tabbed.c b/tabbed.c 28index b15f9cb..6e50c41 100644 29--- a/tabbed.c 30+++ b/tabbed.c 31@@ -15,6 +15,7 @@ 32 #include <X11/Xproto.h> 33 #include <X11/Xutil.h> 34 #include <X11/XKBlib.h> 35+#include <X11/Xft/Xft.h> 36 37 #include "arg.h" 38 39@@ -64,17 +65,16 @@ typedef struct { 40 41 typedef struct { 42 int x, y, w, h; 43- unsigned long norm[ColLast]; 44- unsigned long sel[ColLast]; 45- unsigned long urg[ColLast]; 46+ XftColor norm[ColLast]; 47+ XftColor sel[ColLast]; 48+ XftColor urg[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@@ -97,7 +97,7 @@ static void unmapnotify(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 *ecalloc(size_t n, size_t size); 68 static void *erealloc(void *o, size_t size); 69 static void expose(const XEvent *e); 70@@ -107,7 +107,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 size); 78 static void initfont(const char *fontstr); 79@@ -220,12 +220,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@@ -315,7 +309,7 @@ die(const char *errstr, ...) { 93 94 void 95 drawbar(void) { 96- unsigned long *col; 97+ XftColor *col; 98 int c, cc, fc, width; 99 char *name = NULL; 100 101@@ -368,12 +362,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@@ -394,13 +389,12 @@ drawtext(const char *text, unsigned long col[ColLast]) { 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+ XSetForeground(dpy, dc.gc, col[ColFG].pixel); 129+ 130+ d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen)); 131+ 132+ XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len); 133+ XftDrawDestroy(d); 134 } 135 136 void * 137@@ -537,15 +531,14 @@ getclient(Window w) { 138 return -1; 139 } 140 141-unsigned long 142+XftColor 143 getcolor(const char *colstr) { 144- Colormap cmap = DefaultColormap(dpy, screen); 145- XColor color; 146+ XftColor color; 147 148- if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) 149+ if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color)) 150 die("tabbed: cannot allocate color '%s'\n", colstr); 151 152- return color.pixel; 153+ return color; 154 } 155 156 int 157@@ -594,41 +587,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) { 158 159 void 160 initfont(const char *fontstr) { 161- char *def, **missing, **font_names; 162- int i, n; 163- XFontStruct **xfonts; 164- 165- missing = NULL; 166- if(dc.font.set) 167- XFreeFontSet(dpy, dc.font.set); 168- 169- dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); 170- if(missing) { 171- while(n--) 172- fprintf(stderr, "tabbed: missing fontset: %s\n", missing[n]); 173- XFreeStringList(missing); 174- } 175- 176- if(dc.font.set) { 177- dc.font.ascent = dc.font.descent = 0; 178- n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); 179- for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { 180- dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); 181- dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent); 182- xfonts++; 183- } 184- } else { 185- if(dc.font.xfont) 186- XFreeFont(dpy, dc.font.xfont); 187- dc.font.xfont = NULL; 188- if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) 189- && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) { 190- die("tabbed: cannot load font: '%s'\n", fontstr); 191- } 192+ if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr)) && !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed"))) 193+ die("error, cannot load font: '%s'\n", fontstr); 194 195- dc.font.ascent = dc.font.xfont->ascent; 196- dc.font.descent = dc.font.xfont->descent; 197- } 198+ dc.font.ascent = dc.font.xfont->ascent; 199+ dc.font.descent = dc.font.xfont->descent; 200 dc.font.height = dc.font.ascent + dc.font.descent; 201 } 202 203@@ -1000,11 +963,9 @@ setup(void) { 204 dc.drawable = XCreatePixmap(dpy, root, ww, wh, 205 DefaultDepth(dpy, screen)); 206 dc.gc = XCreateGC(dpy, root, 0, 0); 207- if(!dc.font.set) 208- XSetFont(dpy, dc.gc, dc.font.xfont->fid); 209 210 win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0, 211- dc.norm[ColFG], dc.norm[ColBG]); 212+ dc.norm[ColFG].pixel, dc.norm[ColBG].pixel); 213 XMapRaised(dpy, win); 214 XSelectInput(dpy, win, SubstructureNotifyMask|FocusChangeMask| 215 ButtonPressMask|ExposureMask|KeyPressMask|PropertyChangeMask| 216@@ -1070,15 +1031,9 @@ spawn(const Arg *arg) { 217 218 int 219 textnw(const char *text, unsigned int len) { 220- XRectangle r; 221- 222- if(dc.font.set) { 223- XmbTextExtents(dc.font.set, text, len, NULL, &r); 224- 225- return r.width; 226- } 227- 228- return XTextWidth(dc.font.xfont, text, len); 229+ XGlyphInfo ext; 230+ XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext); 231+ return ext.xOff; 232 } 233 234 void