sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-pango-20200428-f09418b.diff (19188B)


      1 From c48056710a4ca6a6e52be60b0165313f9461f663 Mon Sep 17 00:00:00 2001
      2 From: Marius Iacob <themariusus@gmail.com>
      3 Date: Tue, 28 Apr 2020 17:18:32 +0300
      4 Subject: [PATCH] Using pango markup for status text
      5 
      6 Use a single font string. Removed some utf8 code from drw.
      7 Created for pango 1.44. Older versions might not have getter
      8 for font height, ascent + descent can be used instead.
      9 All texts are rendered with pango but only status is with
     10 markup. Doubled stext size (in case a lot of markup is used).
     11 MIN/MAX is already defined (didn't redefine them).
     12 ---
     13  config.def.h |   2 +-
     14  config.mk    |   4 +-
     15  drw.c        | 303 +++++++++++++--------------------------------------
     16  drw.h        |  17 ++-
     17  dwm.c        |  28 ++---
     18  util.h       |   4 +
     19  6 files changed, 106 insertions(+), 252 deletions(-)
     20 
     21 diff --git a/config.def.h b/config.def.h
     22 index 1c0b587..d201ae6 100644
     23 --- a/config.def.h
     24 +++ b/config.def.h
     25 @@ -5,7 +5,7 @@ static const unsigned int borderpx  = 1;        /* border pixel of windows */
     26  static const unsigned int snap      = 32;       /* snap pixel */
     27  static const int showbar            = 1;        /* 0 means no bar */
     28  static const int topbar             = 1;        /* 0 means bottom bar */
     29 -static const char *fonts[]          = { "monospace:size=10" };
     30 +static const char font[]            = "monospace 10";
     31  static const char dmenufont[]       = "monospace:size=10";
     32  static const char col_gray1[]       = "#222222";
     33  static const char col_gray2[]       = "#444444";
     34 diff --git a/config.mk b/config.mk
     35 index 7084c33..b5c7e12 100644
     36 --- a/config.mk
     37 +++ b/config.mk
     38 @@ -21,8 +21,8 @@ FREETYPEINC = /usr/include/freetype2
     39  #FREETYPEINC = ${X11INC}/freetype2
     40  
     41  # includes and libs
     42 -INCS = -I${X11INC} -I${FREETYPEINC}
     43 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
     44 +INCS = -I${X11INC} -I${FREETYPEINC} `pkg-config --cflags xft pango pangoxft`
     45 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} `pkg-config --libs xft pango pangoxft`
     46  
     47  # flags
     48  CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
     49 diff --git a/drw.c b/drw.c
     50 index 8fd1ca4..6d1b64e 100644
     51 --- a/drw.c
     52 +++ b/drw.c
     53 @@ -4,62 +4,12 @@
     54  #include <string.h>
     55  #include <X11/Xlib.h>
     56  #include <X11/Xft/Xft.h>
     57 +#include <pango/pango.h>
     58 +#include <pango/pangoxft.h>
     59  
     60  #include "drw.h"
     61  #include "util.h"
     62  
     63 -#define UTF_INVALID 0xFFFD
     64 -#define UTF_SIZ     4
     65 -
     66 -static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80,    0, 0xC0, 0xE0, 0xF0};
     67 -static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
     68 -static const long utfmin[UTF_SIZ + 1] = {       0,    0,  0x80,  0x800,  0x10000};
     69 -static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
     70 -
     71 -static long
     72 -utf8decodebyte(const char c, size_t *i)
     73 -{
     74 -	for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
     75 -		if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
     76 -			return (unsigned char)c & ~utfmask[*i];
     77 -	return 0;
     78 -}
     79 -
     80 -static size_t
     81 -utf8validate(long *u, size_t i)
     82 -{
     83 -	if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
     84 -		*u = UTF_INVALID;
     85 -	for (i = 1; *u > utfmax[i]; ++i)
     86 -		;
     87 -	return i;
     88 -}
     89 -
     90 -static size_t
     91 -utf8decode(const char *c, long *u, size_t clen)
     92 -{
     93 -	size_t i, j, len, type;
     94 -	long udecoded;
     95 -
     96 -	*u = UTF_INVALID;
     97 -	if (!clen)
     98 -		return 0;
     99 -	udecoded = utf8decodebyte(c[0], &len);
    100 -	if (!BETWEEN(len, 1, UTF_SIZ))
    101 -		return 1;
    102 -	for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
    103 -		udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
    104 -		if (type)
    105 -			return j;
    106 -	}
    107 -	if (j < len)
    108 -		return 0;
    109 -	*u = udecoded;
    110 -	utf8validate(u, len);
    111 -
    112 -	return len;
    113 -}
    114 -
    115  Drw *
    116  drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
    117  {
    118 @@ -99,58 +49,37 @@ drw_free(Drw *drw)
    119  }
    120  
    121  /* This function is an implementation detail. Library users should use
    122 - * drw_fontset_create instead.
    123 + * drw_font_create instead.
    124   */
    125  static Fnt *
    126 -xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
    127 +xfont_create(Drw *drw, const char *fontname)
    128  {
    129  	Fnt *font;
    130 -	XftFont *xfont = NULL;
    131 -	FcPattern *pattern = NULL;
    132 -
    133 -	if (fontname) {
    134 -		/* Using the pattern found at font->xfont->pattern does not yield the
    135 -		 * same substitution results as using the pattern returned by
    136 -		 * FcNameParse; using the latter results in the desired fallback
    137 -		 * behaviour whereas the former just results in missing-character
    138 -		 * rectangles being drawn, at least with some fonts. */
    139 -		if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
    140 -			fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
    141 -			return NULL;
    142 -		}
    143 -		if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
    144 -			fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
    145 -			XftFontClose(drw->dpy, xfont);
    146 -			return NULL;
    147 -		}
    148 -	} else if (fontpattern) {
    149 -		if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
    150 -			fprintf(stderr, "error, cannot load font from pattern.\n");
    151 -			return NULL;
    152 -		}
    153 -	} else {
    154 -		die("no font specified.");
    155 -	}
    156 +	PangoFontMap *fontmap;
    157 +	PangoContext *context;
    158 +	PangoFontDescription *desc;
    159 +	PangoFontMetrics *metrics;
    160  
    161 -	/* Do not allow using color fonts. This is a workaround for a BadLength
    162 -	 * error from Xft with color glyphs. Modelled on the Xterm workaround. See
    163 -	 * https://bugzilla.redhat.com/show_bug.cgi?id=1498269
    164 -	 * https://lists.suckless.org/dev/1701/30932.html
    165 -	 * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349
    166 -	 * and lots more all over the internet.
    167 -	 */
    168 -	FcBool iscol;
    169 -	if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
    170 -		XftFontClose(drw->dpy, xfont);
    171 -		return NULL;
    172 +
    173 +	if (!fontname) {
    174 +		die("no font specified.");
    175  	}
    176  
    177  	font = ecalloc(1, sizeof(Fnt));
    178 -	font->xfont = xfont;
    179 -	font->pattern = pattern;
    180 -	font->h = xfont->ascent + xfont->descent;
    181  	font->dpy = drw->dpy;
    182  
    183 +	fontmap = pango_xft_get_font_map(drw->dpy, drw->screen);
    184 +	context = pango_font_map_create_context(fontmap);
    185 +	desc = pango_font_description_from_string(fontname);
    186 +	font->layout = pango_layout_new(context);
    187 +	pango_layout_set_font_description(font->layout, desc);
    188 +
    189 +	metrics = pango_context_get_metrics(context, desc, pango_language_from_string ("en-us"));
    190 +	font->h = pango_font_metrics_get_height(metrics) / PANGO_SCALE;
    191 +
    192 +	pango_font_metrics_unref(metrics);
    193 +	g_object_unref(context);
    194 +
    195  	return font;
    196  }
    197  
    198 @@ -159,35 +88,28 @@ xfont_free(Fnt *font)
    199  {
    200  	if (!font)
    201  		return;
    202 -	if (font->pattern)
    203 -		FcPatternDestroy(font->pattern);
    204 -	XftFontClose(font->dpy, font->xfont);
    205 +	if (font->layout)
    206 +		g_object_unref(font->layout);
    207  	free(font);
    208  }
    209  
    210  Fnt*
    211 -drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
    212 +drw_font_create(Drw* drw, const char font[])
    213  {
    214 -	Fnt *cur, *ret = NULL;
    215 -	size_t i;
    216 +	Fnt *fnt = NULL;
    217  
    218 -	if (!drw || !fonts)
    219 +	if (!drw || !font)
    220  		return NULL;
    221  
    222 -	for (i = 1; i <= fontcount; i++) {
    223 -		if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
    224 -			cur->next = ret;
    225 -			ret = cur;
    226 -		}
    227 -	}
    228 -	return (drw->fonts = ret);
    229 +	fnt = xfont_create(drw, font);
    230 +
    231 +	return (drw->font = fnt);
    232  }
    233  
    234  void
    235 -drw_fontset_free(Fnt *font)
    236 +drw_font_free(Fnt *font)
    237  {
    238  	if (font) {
    239 -		drw_fontset_free(font->next);
    240  		xfont_free(font);
    241  	}
    242  }
    243 @@ -221,13 +143,6 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
    244  	return ret;
    245  }
    246  
    247 -void
    248 -drw_setfontset(Drw *drw, Fnt *set)
    249 -{
    250 -	if (drw)
    251 -		drw->fonts = set;
    252 -}
    253 -
    254  void
    255  drw_setscheme(Drw *drw, Clr *scm)
    256  {
    257 @@ -248,24 +163,16 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
    258  }
    259  
    260  int
    261 -drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
    262 +drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup)
    263  {
    264  	char buf[1024];
    265  	int ty;
    266  	unsigned int ew;
    267  	XftDraw *d = NULL;
    268 -	Fnt *usedfont, *curfont, *nextfont;
    269  	size_t i, len;
    270 -	int utf8strlen, utf8charlen, render = x || y || w || h;
    271 -	long utf8codepoint = 0;
    272 -	const char *utf8str;
    273 -	FcCharSet *fccharset;
    274 -	FcPattern *fcpattern;
    275 -	FcPattern *match;
    276 -	XftResult result;
    277 -	int charexists = 0;
    278 -
    279 -	if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
    280 +	int render = x || y || w || h;
    281 +
    282 +	if (!drw || (render && !drw->scheme) || !text || !drw->font)
    283  		return 0;
    284  
    285  	if (!render) {
    286 @@ -280,98 +187,37 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
    287  		w -= lpad;
    288  	}
    289  
    290 -	usedfont = drw->fonts;
    291 -	while (1) {
    292 -		utf8strlen = 0;
    293 -		utf8str = text;
    294 -		nextfont = NULL;
    295 -		while (*text) {
    296 -			utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
    297 -			for (curfont = drw->fonts; curfont; curfont = curfont->next) {
    298 -				charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
    299 -				if (charexists) {
    300 -					if (curfont == usedfont) {
    301 -						utf8strlen += utf8charlen;
    302 -						text += utf8charlen;
    303 -					} else {
    304 -						nextfont = curfont;
    305 -					}
    306 -					break;
    307 -				}
    308 -			}
    309 -
    310 -			if (!charexists || nextfont)
    311 -				break;
    312 -			else
    313 -				charexists = 0;
    314 -		}
    315 -
    316 -		if (utf8strlen) {
    317 -			drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
    318 -			/* shorten text if necessary */
    319 -			for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
    320 -				drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
    321 -
    322 -			if (len) {
    323 -				memcpy(buf, utf8str, len);
    324 -				buf[len] = '\0';
    325 -				if (len < utf8strlen)
    326 -					for (i = len; i && i > len - 3; buf[--i] = '.')
    327 -						; /* NOP */
    328 -
    329 -				if (render) {
    330 -					ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
    331 -					XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
    332 -					                  usedfont->xfont, x, ty, (XftChar8 *)buf, len);
    333 -				}
    334 -				x += ew;
    335 -				w -= ew;
    336 -			}
    337 -		}
    338 -
    339 -		if (!*text) {
    340 -			break;
    341 -		} else if (nextfont) {
    342 -			charexists = 0;
    343 -			usedfont = nextfont;
    344 -		} else {
    345 -			/* Regardless of whether or not a fallback font is found, the
    346 -			 * character must be drawn. */
    347 -			charexists = 1;
    348 -
    349 -			fccharset = FcCharSetCreate();
    350 -			FcCharSetAddChar(fccharset, utf8codepoint);
    351 -
    352 -			if (!drw->fonts->pattern) {
    353 -				/* Refer to the comment in xfont_create for more information. */
    354 -				die("the first font in the cache must be loaded from a font string.");
    355 -			}
    356 -
    357 -			fcpattern = FcPatternDuplicate(drw->fonts->pattern);
    358 -			FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
    359 -			FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
    360 -			FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
    361 -
    362 -			FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
    363 -			FcDefaultSubstitute(fcpattern);
    364 -			match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
    365 -
    366 -			FcCharSetDestroy(fccharset);
    367 -			FcPatternDestroy(fcpattern);
    368 -
    369 -			if (match) {
    370 -				usedfont = xfont_create(drw, NULL, match);
    371 -				if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
    372 -					for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
    373 -						; /* NOP */
    374 -					curfont->next = usedfont;
    375 -				} else {
    376 -					xfont_free(usedfont);
    377 -					usedfont = drw->fonts;
    378 -				}
    379 +	len = strlen(text);
    380 +
    381 +	if (len) {
    382 +		drw_font_getexts(drw->font, text, len, &ew, NULL, markup);
    383 +		/* shorten text if necessary */
    384 +		for (len = MIN(len, sizeof(buf) - 1); len && ew > w; len--)
    385 +			drw_font_getexts(drw->font, text, len, &ew, NULL, markup);
    386 +
    387 +		if (len) {
    388 +			memcpy(buf, text, len);
    389 +			buf[len] = '\0';
    390 +			if (len < strlen(text))
    391 +				for (i = len; i && i > len - 3; buf[--i] = '.')
    392 +					; /* NOP */
    393 +
    394 +			if (render) {
    395 +				ty = y + (h - drw->font->h) / 2;
    396 +				if(markup)
    397 +					pango_layout_set_markup(drw->font->layout, buf, len);
    398 +				else
    399 +					pango_layout_set_text(drw->font->layout, buf, len);
    400 +				pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
    401 +					drw->font->layout, x * PANGO_SCALE, ty * PANGO_SCALE);
    402 +				if(markup) /* clear markup attributes */
    403 +					pango_layout_set_attributes(drw->font->layout, NULL);
    404  			}
    405 +			x += ew;
    406 +			w -= ew;
    407  		}
    408  	}
    409 +
    410  	if (d)
    411  		XftDrawDestroy(d);
    412  
    413 @@ -389,24 +235,29 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
    414  }
    415  
    416  unsigned int
    417 -drw_fontset_getwidth(Drw *drw, const char *text)
    418 +drw_font_getwidth(Drw *drw, const char *text, Bool markup)
    419  {
    420 -	if (!drw || !drw->fonts || !text)
    421 +	if (!drw || !drw->font || !text)
    422  		return 0;
    423 -	return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
    424 +	return drw_text(drw, 0, 0, 0, 0, 0, text, 0, markup);
    425  }
    426  
    427  void
    428 -drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
    429 +drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup)
    430  {
    431 -	XGlyphInfo ext;
    432 -
    433  	if (!font || !text)
    434  		return;
    435  
    436 -	XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
    437 +	PangoRectangle r;
    438 +	if(markup)
    439 +		pango_layout_set_markup(font->layout, text, len);
    440 +	else
    441 +		pango_layout_set_text(font->layout, text, len);
    442 +	pango_layout_get_extents(font->layout, 0, &r);
    443 +	if(markup) /* clear markup attributes */
    444 +		pango_layout_set_attributes(font->layout, NULL);
    445  	if (w)
    446 -		*w = ext.xOff;
    447 +		*w = r.width / PANGO_SCALE;
    448  	if (h)
    449  		*h = font->h;
    450  }
    451 diff --git a/drw.h b/drw.h
    452 index 4bcd5ad..3d3a906 100644
    453 --- a/drw.h
    454 +++ b/drw.h
    455 @@ -7,9 +7,7 @@ typedef struct {
    456  typedef struct Fnt {
    457  	Display *dpy;
    458  	unsigned int h;
    459 -	XftFont *xfont;
    460 -	FcPattern *pattern;
    461 -	struct Fnt *next;
    462 +	PangoLayout *layout;
    463  } Fnt;
    464  
    465  enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
    466 @@ -23,7 +21,7 @@ typedef struct {
    467  	Drawable drawable;
    468  	GC gc;
    469  	Clr *scheme;
    470 -	Fnt *fonts;
    471 +	Fnt *font;
    472  } Drw;
    473  
    474  /* Drawable abstraction */
    475 @@ -32,10 +30,10 @@ void drw_resize(Drw *drw, unsigned int w, unsigned int h);
    476  void drw_free(Drw *drw);
    477  
    478  /* Fnt abstraction */
    479 -Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
    480 -void drw_fontset_free(Fnt* set);
    481 -unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
    482 -void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
    483 +Fnt *drw_font_create(Drw* drw, const char font[]);
    484 +void drw_font_free(Fnt* set);
    485 +unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup);
    486 +void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup);
    487  
    488  /* Colorscheme abstraction */
    489  void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
    490 @@ -46,12 +44,11 @@ Cur *drw_cur_create(Drw *drw, int shape);
    491  void drw_cur_free(Drw *drw, Cur *cursor);
    492  
    493  /* Drawing context manipulation */
    494 -void drw_setfontset(Drw *drw, Fnt *set);
    495  void drw_setscheme(Drw *drw, Clr *scm);
    496  
    497  /* Drawing functions */
    498  void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
    499 -int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
    500 +int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup);
    501  
    502  /* Map functions */
    503  void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
    504 diff --git a/dwm.c b/dwm.c
    505 index 9fd0286..cc180c4 100644
    506 --- a/dwm.c
    507 +++ b/dwm.c
    508 @@ -40,6 +40,7 @@
    509  #include <X11/extensions/Xinerama.h>
    510  #endif /* XINERAMA */
    511  #include <X11/Xft/Xft.h>
    512 +#include <pango/pango.h>
    513  
    514  #include "drw.h"
    515  #include "util.h"
    516 @@ -55,7 +56,8 @@
    517  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
    518  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
    519  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
    520 -#define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
    521 +#define TEXTW(X)                (drw_font_getwidth(drw, (X), False) + lrpad)
    522 +#define TEXTWM(X)                (drw_font_getwidth(drw, (X), True) + lrpad)
    523  
    524  /* enums */
    525  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
    526 @@ -237,7 +239,7 @@ static void zoom(const Arg *arg);
    527  
    528  /* variables */
    529  static const char broken[] = "broken";
    530 -static char stext[256];
    531 +static char stext[512];
    532  static int screen;
    533  static int sw, sh;           /* X display screen geometry width, height */
    534  static int bh, blw = 0;      /* bar geometry */
    535 @@ -440,7 +442,7 @@ buttonpress(XEvent *e)
    536  			arg.ui = 1 << i;
    537  		} else if (ev->x < x + blw)
    538  			click = ClkLtSymbol;
    539 -		else if (ev->x > selmon->ww - TEXTW(stext))
    540 +		else if (ev->x > selmon->ww - TEXTWM(stext))
    541  			click = ClkStatusText;
    542  		else
    543  			click = ClkWinTitle;
    544 @@ -697,16 +699,16 @@ void
    545  drawbar(Monitor *m)
    546  {
    547  	int x, w, tw = 0;
    548 -	int boxs = drw->fonts->h / 9;
    549 -	int boxw = drw->fonts->h / 6 + 2;
    550 +	int boxs = drw->font->h / 9;
    551 +	int boxw = drw->font->h / 6 + 2;
    552  	unsigned int i, occ = 0, urg = 0;
    553  	Client *c;
    554  
    555  	/* draw status first so it can be overdrawn by tags later */
    556  	if (m == selmon) { /* status is only drawn on selected monitor */
    557  		drw_setscheme(drw, scheme[SchemeNorm]);
    558 -		tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
    559 -		drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
    560 +		tw = TEXTWM(stext) - lrpad + 2; /* 2px right padding */
    561 +		drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0, True);
    562  	}
    563  
    564  	for (c = m->clients; c; c = c->next) {
    565 @@ -718,7 +720,7 @@ drawbar(Monitor *m)
    566  	for (i = 0; i < LENGTH(tags); i++) {
    567  		w = TEXTW(tags[i]);
    568  		drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
    569 -		drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
    570 +		drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i, False);
    571  		if (occ & 1 << i)
    572  			drw_rect(drw, x + boxs, boxs, boxw, boxw,
    573  				m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
    574 @@ -727,12 +729,12 @@ drawbar(Monitor *m)
    575  	}
    576  	w = blw = TEXTW(m->ltsymbol);
    577  	drw_setscheme(drw, scheme[SchemeNorm]);
    578 -	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
    579 +	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0, False);
    580  
    581  	if ((w = m->ww - tw - x) > bh) {
    582  		if (m->sel) {
    583  			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
    584 -			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
    585 +			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False);
    586  			if (m->sel->isfloating)
    587  				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
    588  		} else {
    589 @@ -1543,10 +1545,10 @@ setup(void)
    590  	sh = DisplayHeight(dpy, screen);
    591  	root = RootWindow(dpy, screen);
    592  	drw = drw_create(dpy, screen, root, sw, sh);
    593 -	if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
    594 +	if (!drw_font_create(drw, font))
    595  		die("no fonts could be loaded.");
    596 -	lrpad = drw->fonts->h;
    597 -	bh = drw->fonts->h + 2;
    598 +	lrpad = drw->font->h;
    599 +	bh = drw->font->h + 2;
    600  	updategeom();
    601  	/* init atoms */
    602  	utf8string = XInternAtom(dpy, "UTF8_STRING", False);
    603 diff --git a/util.h b/util.h
    604 index f633b51..531ab25 100644
    605 --- a/util.h
    606 +++ b/util.h
    607 @@ -1,7 +1,11 @@
    608  /* See LICENSE file for copyright and license details. */
    609  
    610 +#ifndef MAX
    611  #define MAX(A, B)               ((A) > (B) ? (A) : (B))
    612 +#endif
    613 +#ifndef MIN
    614  #define MIN(A, B)               ((A) < (B) ? (A) : (B))
    615 +#endif
    616  #define BETWEEN(X, A, B)        ((A) <= (X) && (X) <= (B))
    617  
    618  void die(const char *fmt, ...);
    619 -- 
    620 2.26.2
    621