aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bardata.c19
-rw-r--r--src/bardata.h2
-rw-r--r--src/tsar.c33
3 files changed, 44 insertions, 10 deletions
diff --git a/src/bardata.c b/src/bardata.c
index f1495ea..b9f221d 100644
--- a/src/bardata.c
+++ b/src/bardata.c
@@ -111,6 +111,25 @@ void set_component(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) {
i++;
continue;
}
+ if (strcmp(argv[i], "-margin") == 0) {
+ int margin = atoi(argv[i + 1]);
+ comp->margin_left = margin;
+ comp->margin_right = margin;
+ i++;
+ continue;
+ }
+ if (strcmp(argv[i], "-margin-left") == 0) {
+ int margin = atoi(argv[i + 1]);
+ comp->margin_left = margin;
+ i++;
+ continue;
+ }
+ if (strcmp(argv[i], "-margin-right") == 0) {
+ int margin = atoi(argv[i + 1]);
+ comp->margin_right = margin;
+ i++;
+ continue;
+ }
if (strcmp(argv[i], "-fg") == 0) {
const char* col_str = argv[i + 1];
comp->custom_fg = parse_color(col_str);
diff --git a/src/bardata.h b/src/bardata.h
index 9ad0d97..bfab709 100644
--- a/src/bardata.h
+++ b/src/bardata.h
@@ -19,6 +19,8 @@ typedef struct {
char name[16];
char data[64];
int flags;
+ int margin_left;
+ int margin_right;
color_t custom_fg, custom_bg;
// if there are custom colors, these point to the above fields. Otherwise, it
// will point to default_fg/bg.
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;
}
}