Remove unnecessary code (fonts)
This commit is contained in:
parent
d34e5e8ef5
commit
e33e206e31
96
src/drw.c
96
src/drw.c
|
@ -10,7 +10,6 @@
|
||||||
// TODO: Include necessary headers in this header.
|
// TODO: Include necessary headers in this header.
|
||||||
#include "drw.h"
|
#include "drw.h"
|
||||||
|
|
||||||
static void drw_fontset_free(Fnt* set);
|
|
||||||
static void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
static void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
||||||
|
|
||||||
Drw *
|
Drw *
|
||||||
|
@ -35,104 +34,9 @@ drw_free(Drw *drw)
|
||||||
{
|
{
|
||||||
XFreePixmap(drw->dpy, drw->drawable);
|
XFreePixmap(drw->dpy, drw->drawable);
|
||||||
XFreeGC(drw->dpy, drw->gc);
|
XFreeGC(drw->dpy, drw->gc);
|
||||||
drw_fontset_free(drw->fonts);
|
|
||||||
free(drw);
|
free(drw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is an implementation detail. Library users should use
|
|
||||||
* drw_fontset_create instead.
|
|
||||||
*/
|
|
||||||
static Fnt *
|
|
||||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fatal("no font specified.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do not allow using color fonts. This is a workaround for a BadLength
|
|
||||||
* error from Xft with color glyphs. Modelled on the Xterm workaround. See
|
|
||||||
* https://bugzilla.redhat.com/show_bug.cgi?id=1498269
|
|
||||||
* https://lists.suckless.org/dev/1701/30932.html
|
|
||||||
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349
|
|
||||||
* and lots more all over the internet.
|
|
||||||
*/
|
|
||||||
FcBool iscol;
|
|
||||||
if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
|
|
||||||
XftFontClose(drw->dpy, xfont);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
font = ecalloc(1, sizeof(Fnt));
|
|
||||||
font->xfont = xfont;
|
|
||||||
font->pattern = pattern;
|
|
||||||
font->h = xfont->ascent + xfont->descent;
|
|
||||||
font->dpy = drw->dpy;
|
|
||||||
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
xfont_free(Fnt *font)
|
|
||||||
{
|
|
||||||
if (!font)
|
|
||||||
return;
|
|
||||||
if (font->pattern)
|
|
||||||
FcPatternDestroy(font->pattern);
|
|
||||||
XftFontClose(font->dpy, font->xfont);
|
|
||||||
free(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
Fnt*
|
|
||||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
|
||||||
{
|
|
||||||
Fnt *cur, *ret = NULL;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!drw || !fonts)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (i = 1; i <= fontcount; i++) {
|
|
||||||
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
|
|
||||||
cur->next = ret;
|
|
||||||
ret = cur;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (drw->fonts = ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_fontset_free(Fnt *font)
|
|
||||||
{
|
|
||||||
if (font) {
|
|
||||||
drw_fontset_free(font->next);
|
|
||||||
xfont_free(font);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||||
{
|
{
|
||||||
|
|
12
src/drw.h
12
src/drw.h
|
@ -5,14 +5,6 @@ typedef struct {
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
} Cur;
|
} Cur;
|
||||||
|
|
||||||
typedef struct Fnt {
|
|
||||||
Display *dpy;
|
|
||||||
unsigned int h;
|
|
||||||
XftFont *xfont;
|
|
||||||
FcPattern *pattern;
|
|
||||||
struct Fnt *next;
|
|
||||||
} Fnt;
|
|
||||||
|
|
||||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
||||||
typedef XftColor Clr;
|
typedef XftColor Clr;
|
||||||
|
|
||||||
|
@ -24,16 +16,12 @@ typedef struct {
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
GC gc;
|
GC gc;
|
||||||
Clr *scheme;
|
Clr *scheme;
|
||||||
Fnt *fonts;
|
|
||||||
} Drw;
|
} Drw;
|
||||||
|
|
||||||
/* Drawable abstraction */
|
/* Drawable abstraction */
|
||||||
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
||||||
void drw_free(Drw *drw);
|
void drw_free(Drw *drw);
|
||||||
|
|
||||||
/* Fnt abstraction */
|
|
||||||
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
|
|
||||||
|
|
||||||
/* Colorscheme abstraction */
|
/* Colorscheme abstraction */
|
||||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,6 @@ static void (*handler[LASTEvent])(XEvent*) = {
|
||||||
* configuration, allows nested code to access above variables *
|
* configuration, allows nested code to access above variables *
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
|
||||||
static const char *fonts[] = { "monospace:size=10" };
|
|
||||||
static const char col_gray1[] = "#222222";
|
static const char col_gray1[] = "#222222";
|
||||||
static const char col_gray2[] = "#444444";
|
static const char col_gray2[] = "#444444";
|
||||||
static const char col_gray3[] = "#bbbbbb";
|
static const char col_gray3[] = "#bbbbbb";
|
||||||
|
@ -363,8 +362,6 @@ int dwm_main(const char *const new_program_title)
|
||||||
xbase->screen_sizes.h
|
xbase->screen_sizes.h
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
|
||||||
fatal("no fonts could be loaded.");
|
|
||||||
updategeom();
|
updategeom();
|
||||||
/* init cursors */
|
/* init cursors */
|
||||||
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
|
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
|
||||||
|
|
Loading…
Reference in New Issue