aboutsummaryrefslogtreecommitdiff
path: root/src/tsar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tsar.c')
-rw-r--r--src/tsar.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/tsar.c b/src/tsar.c
index 39e3717..cfe5c13 100644
--- a/src/tsar.c
+++ b/src/tsar.c
@@ -33,6 +33,7 @@ void die(const char* fmt, ...) {
exit(err_code);
}
+
size_t utf8_strlen(const char *s) {
size_t len = 0;
while (*s) {
@@ -107,11 +108,9 @@ void deinit_x(void) {
}
void draw_text(
- const char* text,
+ comp_t *comp,
int x,
- int y,
- const XftColor* fg_color,
- const XftColor* bg_color
+ int y
) {
XftDraw* xft_draw = XftDrawCreate(
display,
@@ -120,11 +119,23 @@ void draw_text(
DefaultColormap(display, DefaultScreen(display))
);
- size_t width = font->max_advance_width * utf8_strlen(text);
- XftDrawRect(xft_draw, bg_color, x, y, width, bar_height);
+ size_t width = font->max_advance_width * utf8_strlen(comp->data);
+ width += comp->margin_left + comp->margin_right;
+
+ XftDrawRect(xft_draw, comp->bg, x, y, width, bar_height);
+
+ x += comp->margin_left;
int dy = y + (bar_height - font->height) / 2 + font->ascent;
- XftDrawStringUtf8(xft_draw, fg_color, font, x, dy, (const FcChar8*)text, strlen(text));
+ XftDrawStringUtf8(
+ xft_draw,
+ comp->fg,
+ font,
+ x,
+ dy,
+ (const FcChar8*)comp->data,
+ strlen(comp->data)
+ );
XftDrawDestroy(xft_draw);
}
@@ -133,7 +144,8 @@ void draw_comp_set(float pos_ratio, comp_t **set, int size) {
int width = (size - 1) * comp_gap;
for (int i = 0; i < size; i++) {
comp_t *comp = set[i];
- width += font->max_advance_width * utf8_strlen(comp->data);
+ int margin = comp->margin_left + comp->margin_right;
+ width += font->max_advance_width * utf8_strlen(comp->data) + margin;
}
int x = (bar_width - width) * pos_ratio;
@@ -142,9 +154,10 @@ void draw_comp_set(float pos_ratio, comp_t **set, int size) {
int y = 0;//(bar_height - font->height) / 2;
for (int i = 0; i < size; i++) {
comp_t *comp = set[i];
+ draw_text(comp, x, y);
- draw_text(comp->data, x, y, comp->fg, comp->bg);
- x += font->max_advance_width * utf8_strlen(comp->data);
+ int margin = comp->margin_left + comp->margin_right;
+ x += font->max_advance_width * utf8_strlen(comp->data) + margin;
x += comp_gap;
}
}