From e33e206e314b37b30a1bdb1d3bf9cfff28b08517 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 9 Sep 2022 23:48:57 +0400 Subject: [PATCH] Remove unnecessary code (fonts) --- src/drw.c | 96 ------------------------------------------------------- src/drw.h | 12 ------- src/dwm.c | 3 -- 3 files changed, 111 deletions(-) diff --git a/src/drw.c b/src/drw.c index 1b89e0e..1a7e6da 100644 --- a/src/drw.c +++ b/src/drw.c @@ -10,7 +10,6 @@ // TODO: Include necessary headers in this header. #include "drw.h" -static void drw_fontset_free(Fnt* set); static void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); Drw * @@ -35,104 +34,9 @@ drw_free(Drw *drw) { XFreePixmap(drw->dpy, drw->drawable); XFreeGC(drw->dpy, drw->gc); - drw_fontset_free(drw->fonts); 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 drw_clr_create(Drw *drw, Clr *dest, const char *clrname) { diff --git a/src/drw.h b/src/drw.h index 3e25bb4..8433b3b 100644 --- a/src/drw.h +++ b/src/drw.h @@ -5,14 +5,6 @@ typedef struct { Cursor cursor; } Cur; -typedef struct Fnt { - Display *dpy; - unsigned int h; - XftFont *xfont; - FcPattern *pattern; - struct Fnt *next; -} Fnt; - enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */ typedef XftColor Clr; @@ -24,16 +16,12 @@ typedef struct { Drawable drawable; GC gc; Clr *scheme; - Fnt *fonts; } Drw; /* Drawable abstraction */ Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); void drw_free(Drw *drw); -/* Fnt abstraction */ -Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); - /* Colorscheme abstraction */ Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); diff --git a/src/dwm.c b/src/dwm.c index 10dce97..8639d6e 100644 --- a/src/dwm.c +++ b/src/dwm.c @@ -256,7 +256,6 @@ static void (*handler[LASTEvent])(XEvent*) = { * 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_gray2[] = "#444444"; static const char col_gray3[] = "#bbbbbb"; @@ -363,8 +362,6 @@ int dwm_main(const char *const new_program_title) xbase->screen_sizes.h ); - if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) - fatal("no fonts could be loaded."); updategeom(); /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);