aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-19 14:28:18 +0100
committerFederico Angelilli <code@fedang.net>2023-11-19 14:28:18 +0100
commit89b205f3138b94325458ab121d5adb4a00091860 (patch)
treeb536773d235ec6ce8be37b2cce781c70441aa523
parente774c39c76379738e383e23938f3762b1a57e3b2 (diff)
Add custom bar color
-rw-r--r--src/comet.c11
-rw-r--r--src/draw.c13
-rw-r--r--src/draw.h6
3 files changed, 19 insertions, 11 deletions
diff --git a/src/comet.c b/src/comet.c
index 53f4eff..36d517a 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -63,12 +63,13 @@ int main(int argc, char **argv)
log_debug("Calculated dimensions [height=%d, x_pad=%d, y_pad=%d]", height, x_padding, y_padding);
- Drawable *draw = draw_create("Hack 13 Bold", height, x_padding, x_padding, y_padding, 1, 0);
+ Color background_all = { 0.3, 0.3, 0.3, 1 };
+ Drawable *draw = draw_create("Hack 13 Bold", height, x_padding, x_padding, y_padding, 0);
+ draw_set_background(draw, background_all);
State *state = state_create(win, draw);
- // purple
- Color background = { 0.502, 0.168, 0.886, 1 };
+ Color background = { 0.4, 0.4, 0.4, 1 };
Color foreground = { 0.8, 0.8, 0.8, 1 };
Color stroke = { 0.8, 0.8, 0.8, 1 };
@@ -90,8 +91,10 @@ int main(int argc, char **argv)
button_set_action(date_btn, action);
state_add_button(state, date_btn);
+ // purple
+ Color background2 = { 0.502, 0.168, 0.886, 1 };
Button *u_btn = button_create("U", PANGO_ALIGN_RIGHT);
- button_set_colors(u_btn, background, foreground, stroke);
+ button_set_colors(u_btn, background2, foreground, stroke);
button_set_action(u_btn, action);
state_add_button(state, u_btn);
diff --git a/src/draw.c b/src/draw.c
index 8b4d329..0961f6f 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -18,7 +18,7 @@ static void layout_destroy(Layout *layout)
g_free(layout);
}
-Drawable *draw_create(const char *font, int height, int left_pad, int right_pad, int top_pad, double alpha, int line_w)
+Drawable *draw_create(const char *font, int height, int left_pad, int right_pad, int top_pad, int line_w)
{
Drawable *draw = g_malloc(sizeof(Drawable));
g_assert_nonnull(draw);
@@ -31,13 +31,11 @@ Drawable *draw_create(const char *font, int height, int left_pad, int right_pad,
draw->left_pad = left_pad;
draw->right_pad = right_pad;
draw->top_pad = top_pad;
- draw->alpha = alpha;
- g_assert(alpha >= 0 && alpha <= 1);
draw->line_w = line_w;
draw->layouts = NULL;
- log_debug("Draw context created [height=%d, left_pad=%d, right_pad=%d, top_pad=%d, alpha=%.2lf]", height, left_pad, right_pad, top_pad, alpha);
+ log_debug("Draw context created [height=%d, left_pad=%d, right_pad=%d, top_pad=%d, line_w=%d]", height, left_pad, right_pad, top_pad, line_w);
return draw;
}
@@ -73,7 +71,7 @@ void draw_paint(Drawable *draw, Window *win)
int radius = height / 2;
double degree = M_PI / 180.0;
- cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, draw->alpha);
+ cairo_set_source_rgba(cr, draw->background.r, draw->background.g, draw->background.b, draw->background.a);
// TODO: Here we should paint the shape of the bar, however there is a problem with the surface
// painted in the pixmap to mask the window shape in window_paint_corners.
@@ -252,6 +250,11 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns)
g_list_free(btns);
}
+void draw_set_background(Drawable *draw, Color background)
+{
+ draw->background = background;
+}
+
void draw_destroy(Drawable *draw)
{
g_list_free_full(draw->layouts, (GDestroyNotify)layout_destroy);
diff --git a/src/draw.h b/src/draw.h
index 35a9f68..47ff02d 100644
--- a/src/draw.h
+++ b/src/draw.h
@@ -15,8 +15,8 @@ struct Drawable {
int left_pad;
int right_pad;
int top_pad;
- double alpha;
int line_w;
+ Color background;
GList *layouts;
PangoFontDescription *desc;
};
@@ -29,12 +29,14 @@ typedef struct {
PangoLayout *pl;
} Layout;
-Drawable *draw_create(const char *font, int height, int left_pad, int right_pad, int top_pad, double alpha, int line_w);
+Drawable *draw_create(const char *font, int height, int left_pad, int right_pad, int top_pad, int line_w);
void draw_compute_layout(Drawable *draw, Window *win, GList *btns);
void draw_paint(Drawable *draw, Window *win);
+void draw_set_background(Drawable *draw, Color background);
+
void draw_destroy(Drawable *draw);
#endif