reverting to plain X11 fonts in order to implement draw.c default 61fe833a
anselm@garbe.us · 2012-11-18 10:56 3 file(s) · +68 −38
config.def.h +1 −1
1 1
/* See LICENSE file for copyright and license details. */
2 2
3 3
/* appearance */
4 -
static const char font[]            = "Liberation Mono:pixelsize=12:antialias=false:autohint=false";
4 +
static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
5 5
static const char normbordercolor[] = "#444444";
6 6
static const char normbgcolor[]     = "#222222";
7 7
static const char normfgcolor[]     = "#bbbbbb";
config.mk +2 −2
15 15
XINERAMAFLAGS = -DXINERAMA
16 16
17 17
# includes and libs
18 -
INCS = -I${X11INC} -I/usr/include/freetype2
19 -
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} -lutil -lXext -lXft -lfontconfig
18 +
INCS = -I${X11INC}
19 +
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
20 20
21 21
# flags
22 22
CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
dwm.c +65 −35
37 37
#include <X11/Xproto.h>
38 38
#include <X11/Xutil.h>
39 39
#include <X11/XKBlib.h>
40 -
#include <fontconfig/fontconfig.h>
41 -
#include <X11/Xft/Xft.h>
42 40
#ifdef XINERAMA
43 41
#include <X11/extensions/Xinerama.h>
44 42
#endif /* XINERAMA */
104 102
105 103
typedef struct {
106 104
	int x, y, w, h;
107 -
	XftColor norm[ColLast];
108 -
	XftColor sel[ColLast];
105 +
	unsigned long norm[ColLast];
106 +
	unsigned long sel[ColLast];
109 107
	Drawable drawable;
110 108
	GC gc;
111 109
	struct {
112 110
		int ascent;
113 111
		int descent;
114 112
		int height;
115 -
		XftFont *xfont;
113 +
		XFontSet set;
114 +
		XFontStruct *xfont;
116 115
	} font;
117 116
} DC; /* draw context */
118 117
182 181
static Monitor *dirtomon(int dir);
183 182
static void drawbar(Monitor *m);
184 183
static void drawbars(void);
185 -
static void drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]);
186 -
static void drawtext(const char *text, XftColor col[ColLast], Bool invert);
184 +
static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
185 +
static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
187 186
static void enternotify(XEvent *e);
188 187
static void expose(XEvent *e);
189 188
static void focus(Client *c);
190 189
static void focusin(XEvent *e);
191 190
static void focusmon(const Arg *arg);
192 191
static void focusstack(const Arg *arg);
193 -
static XftColor getcolor(const char *colstr);
192 +
static unsigned long getcolor(const char *colstr);
194 193
static Bool getrootptr(int *x, int *y);
195 194
static long getstate(Window w);
196 195
static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
490 489
	for(m = mons; m; m = m->next)
491 490
		while(m->stack)
492 491
			unmanage(m->stack, False);
492 +
	if(dc.font.set)
493 +
		XFreeFontSet(dpy, dc.font.set);
494 +
	else
495 +
		XFreeFont(dpy, dc.font.xfont);
493 496
	XUngrabKey(dpy, AnyKey, AnyModifier, root);
494 497
	XFreePixmap(dpy, dc.drawable);
495 498
	XFreeGC(dpy, dc.gc);
722 725
drawbar(Monitor *m) {
723 726
	int x;
724 727
	unsigned int i, occ = 0, urg = 0;
725 -
	XftColor *col;
728 +
	unsigned long *col;
726 729
	Client *c;
727 730
728 731
	for(c = m->clients; c; c = c->next) {
777 780
}
778 781
779 782
void
780 -
drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) {
783 +
drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
781 784
	int x;
782 785
783 -
	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG].pixel);
786 +
	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
784 787
	x = (dc.font.ascent + dc.font.descent + 2) / 4;
785 788
	if(filled)
786 789
		XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1);
789 792
}
790 793
791 794
void
792 -
drawtext(const char *text, XftColor col[ColLast], Bool invert) {
795 +
drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
793 796
	char buf[256];
794 797
	int i, x, y, h, len, olen;
795 -
	XftDraw *d;
796 798
797 -
	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG].pixel);
799 +
	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
798 800
	XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
799 801
	if(!text)
800 802
		return;
809 811
	memcpy(buf, text, len);
810 812
	if(len < olen)
811 813
		for(i = len; i && i > len - 3; buf[--i] = '.');
812 -
813 -
	d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen));
814 -
815 -
	XftDrawStringUtf8(d, &col[invert ? ColBG : ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
816 -
	XftDrawDestroy(d);
814 +
	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
815 +
	if(dc.font.set)
816 +
		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
817 +
	else
818 +
		XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
817 819
}
818 820
819 821
void
859 861
		detachstack(c);
860 862
		attachstack(c);
861 863
		grabbuttons(c, True);
862 -
		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder].pixel);
864 +
		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
863 865
		setfocus(c);
864 866
	}
865 867
	else {
933 935
	return atom;
934 936
}
935 937
936 -
XftColor 
938 +
unsigned long
937 939
getcolor(const char *colstr) {
938 -
	XftColor color;
940 +
	Colormap cmap = DefaultColormap(dpy, screen);
941 +
	XColor color;
939 942
940 -
	if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
943 +
	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
941 944
		die("error, cannot allocate color '%s'\n", colstr);
942 -
943 -
	return color;
945 +
	return color.pixel;
944 946
}
945 947
946 948
Bool
1041 1043
1042 1044
void
1043 1045
initfont(const char *fontstr) {
1046 +
	char *def, **missing;
1047 +
	int n;
1044 1048
1045 -
	if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr))
1046 -
	&& !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed")))
1047 -
		die("error, cannot load font: '%s'\n", fontstr);
1049 +
	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
1050 +
	if(missing) {
1051 +
		while(n--)
1052 +
			fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
1053 +
		XFreeStringList(missing);
1054 +
	}
1055 +
	if(dc.font.set) {
1056 +
		XFontStruct **xfonts;
1057 +
		char **font_names;
1048 1058
1049 -
	dc.font.ascent = dc.font.xfont->ascent;
1050 -
	dc.font.descent = dc.font.xfont->descent;
1059 +
		dc.font.ascent = dc.font.descent = 0;
1060 +
		XExtentsOfFontSet(dc.font.set);
1061 +
		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
1062 +
		while(n--) {
1063 +
			dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
1064 +
			dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
1065 +
			xfonts++;
1066 +
		}
1067 +
	}
1068 +
	else {
1069 +
		if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
1070 +
		&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
1071 +
			die("error, cannot load font: '%s'\n", fontstr);
1072 +
		dc.font.ascent = dc.font.xfont->ascent;
1073 +
		dc.font.descent = dc.font.xfont->descent;
1074 +
	}
1051 1075
	dc.font.height = dc.font.ascent + dc.font.descent;
1052 1076
}
1053 1077
1132 1156
1133 1157
	wc.border_width = c->bw;
1134 1158
	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
1135 -
	XSetWindowBorder(dpy, w, dc.norm[ColBorder].pixel);
1159 +
	XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
1136 1160
	configure(c); /* propagates border_width, if size doesn't change */
1137 1161
	updatewindowtype(c);
1138 1162
	updatesizehints(c);
1622 1646
	dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
1623 1647
	dc.gc = XCreateGC(dpy, root, 0, NULL);
1624 1648
	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
1649 +
	if(!dc.font.set)
1650 +
		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
1625 1651
	/* init bars */
1626 1652
	updatebars();
1627 1653
	updatestatus();
1694 1720
1695 1721
int
1696 1722
textnw(const char *text, unsigned int len) {
1697 -
	XGlyphInfo ext;
1698 -
	XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext);
1699 -
	return ext.xOff;
1723 +
	XRectangle r;
1724 +
1725 +
	if(dc.font.set) {
1726 +
		XmbTextExtents(dc.font.set, text, len, NULL, &r);
1727 +
		return r.width;
1728 +
	}
1729 +
	return XTextWidth(dc.font.xfont, text, len);
1700 1730
}
1701 1731
1702 1732
void
1776 1806
	if(!c)
1777 1807
		return;
1778 1808
	grabbuttons(c, False);
1779 -
	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder].pixel);
1809 +
	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
1780 1810
	if(setfocus) {
1781 1811
		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
1782 1812
		XDeleteProperty(dpy, root, netatom[NetActiveWindow]);