aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2017-12-07 14:57:02 +0100
committerBert Münnich <ber.t@posteo.de>2017-12-07 21:19:53 +0100
commit3c7d6f3528432a433cd368605e4dc6f0fecaa898 (patch)
treed05be3b28e7519ea5d00ea091efa18728992f87a /window.c
parent69b2d3cafdb580a5123747191c4fe92fccc47ced (diff)
Replace utf8codepoint with Chris Wellons' utf8_decode
Code under a different license should be kept in a separate file. This implemention is a single header file with ~65 lines, so it better fits this requirement.
Diffstat (limited to 'window.c')
-rw-r--r--window.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/window.c b/window.c
index d1a96fb..b2d72d1 100644
--- a/window.c
+++ b/window.c
@@ -20,6 +20,7 @@
#define _WINDOW_CONFIG
#include "config.h"
#include "icon/data.h"
+#include "utf8.h"
#include <stdlib.h>
#include <string.h>
@@ -131,8 +132,9 @@ void win_init(win_t *win)
win->bar.l.size = BAR_L_LEN;
win->bar.r.size = BAR_R_LEN;
- win->bar.l.buf = emalloc(win->bar.l.size);
- win->bar.r.buf = emalloc(win->bar.r.size);
+ /* 3 padding bytes needed by utf8_decode */
+ win->bar.l.buf = emalloc(win->bar.l.size + 3);
+ win->bar.r.buf = emalloc(win->bar.r.size + 3);
win->bar.h = options->hide_bar ? 0 : barheight;
INIT_ATOM_(WM_DELETE_WINDOW);
@@ -371,14 +373,14 @@ int win_textwidth(const win_env_t *e, const char *text, unsigned int len, bool w
void win_draw_bar_text(win_t *win, XftDraw *d, XftColor *color, XftFont *font, int x, int y, char *text, int maxlen, int maximum_x)
{
size_t len = 0;
- int xshift = 0, newshift;
- long codep;
+ int err, xshift = 0, newshift;
+ uint32_t codep;
char *p, *nextp;
FcCharSet* fccharset;
XftFont* fallback = NULL;
for (p = text; *p && (len < maxlen); p = nextp, len++) {
- nextp = utf8codepoint(p, &codep);
+ nextp = utf8_decode(p, &codep, &err);
if (!XftCharExists(win->env.dpy, font, codep)) {
fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, codep);