diff options
| -rw-r--r-- | src/pipe.c | 6 | ||||
| -rw-r--r-- | src/tsar.c | 13 |
2 files changed, 16 insertions, 3 deletions
@@ -34,7 +34,7 @@ void await_change(void) { while (argc < MAX_ARGS) { char chr = buff[i]; - if (chr == '\0') { + if (chr == '\0' || chr == '\n') { break; } @@ -57,6 +57,10 @@ void await_change(void) { i++; } + if (chr_on > 0) { + argv[argc][chr_on] = '\0'; + argc++; + } make_change(argv, argc); } @@ -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); } } |
