aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pipe.c6
-rw-r--r--src/tsar.c13
2 files changed, 16 insertions, 3 deletions
diff --git a/src/pipe.c b/src/pipe.c
index 202a89c..70b9483 100644
--- a/src/pipe.c
+++ b/src/pipe.c
@@ -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);
}
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);
}
}