diff options
| -rw-r--r-- | src/button.c | 6 | ||||
| -rw-r--r-- | src/button.h | 3 | ||||
| -rw-r--r-- | src/comet.c | 23 | ||||
| -rw-r--r-- | src/draw.c | 29 |
4 files changed, 47 insertions, 14 deletions
diff --git a/src/button.c b/src/button.c index 0ff1437..2835623 100644 --- a/src/button.c +++ b/src/button.c @@ -56,6 +56,12 @@ void button_group_append(Button *btn, Button *child) CAST(btn, ButtonGroup)->children = g_list_append(CAST(btn, ButtonGroup)->children, child); } +void button_set_padding(Button *btn, int padding) +{ + g_assert(padding >= 0); + btn->padding = padding; +} + void button_destroy(Button *btn) { if (btn->simple) g_free(CAST(btn, ButtonSimple)->text); diff --git a/src/button.h b/src/button.h index aa22001..4f4285f 100644 --- a/src/button.h +++ b/src/button.h @@ -18,6 +18,7 @@ typedef struct { struct Button { bool simple; + int padding; PangoAlignment align; Color color; Color line_color; @@ -53,6 +54,8 @@ Button *button_group_create(PangoAlignment align, Color color, Color line_color) void button_group_append(Button *btn, Button *child); +void button_set_padding(Button *btn, int padding); + void button_destroy(Button *btn); #endif diff --git a/src/comet.c b/src/comet.c index 07fb8cf..737e0f3 100644 --- a/src/comet.c +++ b/src/comet.c @@ -214,7 +214,7 @@ static void register_buttons(State *state, Color color, Color line_color, Color // Cpu usage button Button *cpu_btn = button_simple_create(PANGO_ALIGN_RIGHT, color, line_color); - button_simple_set_text(cpu_btn, "cpu", text_color); + button_simple_set_text(cpu_btn, " ?%", text_color); button_simple_set_action(cpu_btn, show_action, state); state_add_button(state, cpu_btn); @@ -308,18 +308,27 @@ int main(int argc, char **argv) state_add_button(state, q_btn); // Test button group + Color orange = { 1, 0.647, 0, 1 }; + Button *group = button_group_create(PANGO_ALIGN_LEFT, orange, line_color); + Button *child1 = button_simple_create(PANGO_ALIGN_CENTER, color, line_color); - button_simple_set_text(child1, "C1", text_color); - button_simple_set_action(child1, show_action, &date_ctx); + button_set_padding(child1, 1); + button_simple_set_text(child1, "Open", text_color); + button_simple_set_action(child1, show_action, NULL); Button *child2 = button_simple_create(PANGO_ALIGN_CENTER, color, line_color); - button_simple_set_text(child2, "C2", text_color); - button_simple_set_action(child2, show_action, &date_ctx); + button_set_padding(child2, 1); + button_simple_set_text(child2, "Firefox", text_color); + button_simple_set_action(child2, show_action, NULL); + + Button *child3 = button_simple_create(PANGO_ALIGN_CENTER, color, line_color); + button_set_padding(child3, 0); + button_simple_set_text(child3, "Alacritty", text_color); + button_simple_set_action(child3, show_action, NULL); - Color orange = { 1, 0.647, 0, 1 }; - Button *group = button_group_create(PANGO_ALIGN_LEFT, orange, line_color); button_group_append(group, child1); button_group_append(group, child2); + button_group_append(group, child3); state_add_button(state, group); connect_attach_state(con, state); @@ -64,7 +64,6 @@ void draw_paint(Drawable *draw, Window *win) cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - int radius = height / 2; double degree = M_PI / 180.0; cairo_set_source_rgba(cr, draw->background.r, draw->background.g, draw->background.b, draw->background.a); @@ -75,6 +74,7 @@ void draw_paint(Drawable *draw, Window *win) // This is caused by some difference between the two shapes (that should technically be the same) // which causes a mismatch between the two layers and leaves some black pixels visible + //int radius = height / 2; //cairo_arc(cr, radius, radius, radius, 90.0 * degree, 270 * degree); //cairo_arc(cr, width - radius, radius, radius, 270 * degree, 450 * degree); //cairo_fill(cr); @@ -87,6 +87,8 @@ void draw_paint(Drawable *draw, Window *win) for (GList *it = draw->layouts; it; it = it->next) { Layout *layout = it->data; + int radius = layout->height / 2; + Color color = layout->btn->color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_new_sub_path(cr); @@ -192,8 +194,8 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) if (prev != NULL && prev->align == btn->align) x += sep; - layout->x = x; - layout->y = 0; + layout->x = x + btn->padding; + layout->y = btn->padding; draw->layouts = g_list_prepend(draw->layouts, layout); @@ -215,8 +217,8 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) Layout *child = g_malloc(sizeof(Layout)); child->btn = btn; - child->x = x; - child->y = 0; + child->x = x + btn->padding; + child->y = btn->padding;; child->pl = pango_cairo_create_layout(window_get_context(win)); layout_text(child, draw->desc, scale, height, radius); @@ -225,6 +227,9 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) x += child->width + line_w * 2; + child->width -= 2 * btn->padding; + child->height -= 2 * btn->padding; + if (it->next != NULL) x += sep; } @@ -233,8 +238,15 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) layout->height = height; // FIXME: Temporary solution to make the antialiasing (or the circles not overlapping correctly) problem less noticeable - layout->x += 1; - layout->width -= 2; + + bool fix_left = CAST(g_list_first(group->children)->data, Button)->padding == 0; + bool fix_right = CAST(g_list_last(group->children)->data, Button)->padding == 0; + + if (fix_left) { + layout->x += 1; + layout->width -= 1; + } + if (fix_right) layout->width -= 1; goto end; } } @@ -243,6 +255,9 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) layout_text(layout, draw->desc, scale, height, radius); x += layout->width + line_w * 2; + layout->width -= 2 * btn->padding; + layout->height -= 2 * btn->padding; + end: if (prev != NULL && prev->align != btn->align) { if (btn->align == PANGO_ALIGN_CENTER) adjust_center = draw->layouts; |
