aboutsummaryrefslogtreecommitdiff
path: root/src/tsar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tsar.c')
-rw-r--r--src/tsar.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/tsar.c b/src/tsar.c
index 8799421..ae54107 100644
--- a/src/tsar.c
+++ b/src/tsar.c
@@ -35,6 +35,15 @@ void die(const char* fmt, ...) {
exit(err_code);
}
+int utf8_strlen(const char *s) {
+ int len = 0;
+ while (*s) {
+ if ((*s & 0xC0) != 0x80) len++;
+ s++;
+ }
+ return len;
+}
+
void load_font(const char* font_name) {
XftFont* new_font = XftFontOpenName(display, DefaultScreen(display), font_name);
if (new_font == NULL) {
@@ -125,7 +134,7 @@ void draw_comp_set(float pos_ratio, comp_t **set, int size) {
int width = 0;
for (int i = 0; i < size; i++) {
comp_t *comp = set[i];
- width += font->max_advance_width * strlen(comp->data);
+ width += font->max_advance_width * utf8_strlen(comp->data);
}
int x = (bar_width - width) * pos_ratio;
@@ -136,7 +145,7 @@ void draw_comp_set(float pos_ratio, comp_t **set, int size) {
comp_t *comp = set[i];
draw_text(comp->data, x, y);
- x += font->max_advance_width * strlen(comp->data);
+ x += font->max_advance_width * utf8_strlen(comp->data);
}
}