aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-02-12 02:23:42 +0100
committerDuncaen <mail@duncano.de>2018-12-31 23:30:01 +0100
commit5feb57e410e7965581415d13bd74e9183b42c1e2 (patch)
tree1ad56151c45f80e4fc10be82bd9ab0bbafa1186c
parent0b8c2bd23944e0e6bb834400bc934a0073e8dfef (diff)
downloaddwm-5feb57e410e7965581415d13bd74e9183b42c1e2.tar.gz
rip out freetype/xft, bitmap fonts are fine
-rw-r--r--config.def.h4
-rw-r--r--drw.c282
-rw-r--r--drw.h8
-rw-r--r--dwm.c1
4 files changed, 89 insertions, 206 deletions
diff --git a/config.def.h b/config.def.h
index 1c0b587..b0eddf9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -5,8 +5,8 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
-static const char *fonts[] = { "monospace:size=10" };
-static const char dmenufont[] = "monospace:size=10";
+static const char *fonts[] = { "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*" };
+static const char dmenufont[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
diff --git a/drw.c b/drw.c
index c638323..c8f62d4 100644
--- a/drw.c
+++ b/drw.c
@@ -3,63 +3,10 @@
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
-#include <X11/Xft/Xft.h>
#include "drw.h"
#include "util.h"
-#define UTF_INVALID 0xFFFD
-#define UTF_SIZ 4
-
-static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
-static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
-static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
-static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
-
-static long
-utf8decodebyte(const char c, size_t *i)
-{
- for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
- if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
- return (unsigned char)c & ~utfmask[*i];
- return 0;
-}
-
-static size_t
-utf8validate(long *u, size_t i)
-{
- if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
- *u = UTF_INVALID;
- for (i = 1; *u > utfmax[i]; ++i)
- ;
- return i;
-}
-
-static size_t
-utf8decode(const char *c, long *u, size_t clen)
-{
- size_t i, j, len, type;
- long udecoded;
-
- *u = UTF_INVALID;
- if (!clen)
- return 0;
- udecoded = utf8decodebyte(c[0], &len);
- if (!BETWEEN(len, 1, UTF_SIZ))
- return 1;
- for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
- udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
- if (type)
- return j;
- }
- if (j < len)
- return 0;
- *u = udecoded;
- utf8validate(u, len);
-
- return len;
-}
-
Drw *
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
{
@@ -102,40 +49,42 @@ drw_free(Drw *drw)
* drw_fontset_create instead.
*/
static Fnt *
-xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
+xfont_create(Drw *drw, const char *fontname)
{
Fnt *font;
- XftFont *xfont = NULL;
- FcPattern *pattern = NULL;
-
- if (fontname) {
- /* Using the pattern found at font->xfont->pattern does not yield the
- * same substitution results as using the pattern returned by
- * FcNameParse; using the latter results in the desired fallback
- * behaviour whereas the former just results in missing-character
- * rectangles being drawn, at least with some fonts. */
- if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
- fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
- return NULL;
- }
- if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
- fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
- XftFontClose(drw->dpy, xfont);
- return NULL;
- }
- } else if (fontpattern) {
- if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
- fprintf(stderr, "error, cannot load font from pattern.\n");
- return NULL;
+ int n;
+ char *def, **missing;
+
+ printf("create font '%s'\n", fontname);
+
+ font = ecalloc(1, sizeof(Fnt));
+
+ font->set = XCreateFontSet(drw->dpy, fontname, &missing, &n, &def);
+ if (missing) {
+ while(n--)
+ fprintf(stderr, "drw: missing fontset: %s\n", missing[n]);
+ XFreeStringList(missing);
+ }
+
+ if (font->set) {
+ XFontStruct **xfonts;
+ char **font_names;
+ XExtentsOfFontSet(font->set);
+ n = XFontsOfFontSet(font->set, &xfonts, &font_names);
+ while (n--) {
+ font->ascent = MAX(font->ascent, (*xfonts)->ascent);
+ font->descent = MAX(font->descent, (*xfonts)->descent);
+ xfonts++;
}
} else {
- die("no font specified.");
+ if (!(font->xfont = XLoadQueryFont(drw->dpy, fontname))
+ && !(font->xfont = XLoadQueryFont(drw->dpy, "fixed")))
+ die("error, cannot load font: '%s'\n", fontname);
+ font->ascent = font->xfont->ascent;
+ font->descent = font->xfont->descent;
}
- font = ecalloc(1, sizeof(Fnt));
- font->xfont = xfont;
- font->pattern = pattern;
- font->h = xfont->ascent + xfont->descent;
+ font->h = font->ascent + font->descent;
font->dpy = drw->dpy;
return font;
@@ -146,9 +95,10 @@ xfont_free(Fnt *font)
{
if (!font)
return;
- if (font->pattern)
- FcPatternDestroy(font->pattern);
- XftFontClose(font->dpy, font->xfont);
+ if (font->set)
+ XFreeFontSet(font->dpy, font->set);
+ else
+ XFreeFont(font->dpy, font->xfont);
free(font);
}
@@ -162,7 +112,7 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
return NULL;
for (i = 1; i <= fontcount; i++) {
- if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
+ if ((cur = xfont_create(drw, fonts[fontcount - i]))) {
cur->next = ret;
ret = cur;
}
@@ -185,9 +135,8 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
if (!drw || !dest || !clrname)
return;
- if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
- DefaultColormap(drw->dpy, drw->screen),
- clrname, dest))
+ if (!XAllocNamedColor(drw->dpy, DefaultColormap(drw->dpy, drw->screen),
+ clrname, dest, dest))
die("error, cannot allocate color '%s'", clrname);
}
@@ -238,19 +187,10 @@ int
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
{
char buf[1024];
- int ty;
- unsigned int ew;
- XftDraw *d = NULL;
- Fnt *usedfont, *curfont, *nextfont;
- size_t i, len;
- int utf8strlen, utf8charlen, render = x || y || w || h;
- long utf8codepoint = 0;
- const char *utf8str;
- FcCharSet *fccharset;
- FcPattern *fcpattern;
- FcPattern *match;
- XftResult result;
- int charexists = 0;
+ size_t olen;
+ int render = x || y || w || h;
+ unsigned int ew, eh;
+ int i, ty, len;
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
return 0;
@@ -258,108 +198,43 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
if (!render) {
w = ~w;
} else {
- XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
+ XSetForeground(drw->dpy, drw->gc, drw->scheme[!invert ? ColBg : ColFg].pixel);
+ /* XSetBackground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); */
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
- d = XftDrawCreate(drw->dpy, drw->drawable,
- DefaultVisual(drw->dpy, drw->screen),
- DefaultColormap(drw->dpy, drw->screen));
+
x += lpad;
w -= lpad;
}
- usedfont = drw->fonts;
- while (1) {
- utf8strlen = 0;
- utf8str = text;
- nextfont = NULL;
- while (*text) {
- utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
- for (curfont = drw->fonts; curfont; curfont = curfont->next) {
- charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
- if (charexists) {
- if (curfont == usedfont) {
- utf8strlen += utf8charlen;
- text += utf8charlen;
- } else {
- nextfont = curfont;
- }
- break;
- }
- }
-
- if (!charexists || nextfont)
- break;
- else
- charexists = 0;
- }
-
- if (utf8strlen) {
- drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
- /* shorten text if necessary */
- for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
- drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
-
- if (len) {
- memcpy(buf, utf8str, len);
- buf[len] = '\0';
- if (len < utf8strlen)
- for (i = len; i && i > len - 3; buf[--i] = '.')
- ; /* NOP */
-
- if (render) {
- ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
- XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
- usedfont->xfont, x, ty, (XftChar8 *)buf, len);
- }
- x += ew;
- w -= ew;
- }
- }
-
- if (!*text) {
- break;
- } else if (nextfont) {
- charexists = 0;
- usedfont = nextfont;
- } else {
- /* Regardless of whether or not a fallback font is found, the
- * character must be drawn. */
- charexists = 1;
-
- fccharset = FcCharSetCreate();
- FcCharSetAddChar(fccharset, utf8codepoint);
-
- if (!drw->fonts->pattern) {
- /* Refer to the comment in xfont_create for more information. */
- die("the first font in the cache must be loaded from a font string.");
- }
-
- fcpattern = FcPatternDuplicate(drw->fonts->pattern);
- FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
- FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
-
- FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
- FcDefaultSubstitute(fcpattern);
- match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
-
- FcCharSetDestroy(fccharset);
- FcPatternDestroy(fcpattern);
-
- if (match) {
- usedfont = xfont_create(drw, NULL, match);
- if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
- for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
- ; /* NOP */
- curfont->next = usedfont;
- } else {
- xfont_free(usedfont);
- usedfont = drw->fonts;
- }
+ olen = strlen(text);
+ drw_font_getexts(&drw->fonts[0], text, olen, &ew, &eh);
+ /* shorten text if necessary */
+ for (len = MIN(olen, sizeof buf); len && ew > w; len--)
+ drw_font_getexts(&drw->fonts[0], text, len, &ew, &eh);
+
+ if (len) {
+ memcpy(buf, text, len);
+ /* buf[len] = 0; */
+ if (len < olen)
+ for (i = len; i && i > len - 3; buf[--i] = '.')
+ ; /* NOP */
+
+ if (render) {
+ ty = y + (h - drw->fonts[0].h) / 2 + drw->fonts[0].ascent;
+ XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColBg : ColFg].pixel);
+ if (drw->fonts[0].set) {
+#ifdef X_HAVE_UTF8_STRING
+ Xutf8DrawString(drw->dpy, drw->drawable, drw->fonts[0].set, drw->gc, x, ty, buf, len);
+#else
+ XmbDrawString(drw->dpy, drw->drawable, drw->fonts[0].set, drw->gc, x, ty, buf, len);
+#endif
+ } else {
+ XDrawString(drw->dpy, drw->drawable, drw->gc, x, ty, buf, len);
}
}
+ x += ew;
+ w -= ew;
}
- if (d)
- XftDrawDestroy(d);
return x + (render ? w : 0);
}
@@ -385,16 +260,23 @@ drw_fontset_getwidth(Drw *drw, const char *text)
void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
{
- XGlyphInfo ext;
+ XRectangle r;
if (!font || !text)
return;
- XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
- if (w)
- *w = ext.xOff;
- if (h)
+ if(font->set) {
+#ifdef X_HAVE_UTF8_STRING
+ Xutf8TextExtents(font->set, text, len, NULL, &r);
+#else
+ XmbTextExtents(font->set, text, len, NULL, &r);
+#endif
+ *w = r.width;
+ *h = r.height;
+ } else {
+ *w = XTextWidth(font->xfont, text, len);
*h = font->h;
+ }
}
Cur *
diff --git a/drw.h b/drw.h
index 4bcd5ad..d4418cd 100644
--- a/drw.h
+++ b/drw.h
@@ -7,13 +7,15 @@ typedef struct {
typedef struct Fnt {
Display *dpy;
unsigned int h;
- XftFont *xfont;
- FcPattern *pattern;
+ unsigned int ascent;
+ unsigned int descent;
+ XFontStruct *xfont;
+ XFontSet set;
struct Fnt *next;
} Fnt;
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
-typedef XftColor Clr;
+typedef XColor Clr;
typedef struct {
unsigned int w, h;
diff --git a/dwm.c b/dwm.c
index 24bb2cf..3c4406a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -39,7 +39,6 @@
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
-#include <X11/Xft/Xft.h>
#include "drw.h"
#include "util.h"