diff --git a/common/draw.h b/common/draw.h index e3fc50c3f..7a44388c9 100644 --- a/common/draw.h +++ b/common/draw.h @@ -205,7 +205,23 @@ static inline void xcolor_wipe(xcolor_t *color) { if(color) + { p_delete(&color->name); + p_clear(color, 1); + } +} + +static inline xcolor_t +xcolor_copy(xcolor_t *color) +{ + xcolor_t c; + + assert(color); + + c = *color; + c.name = a_strdup(color->name); + + return c; } bool xcolor_new(xcb_connection_t *, int, const char *, xcolor_t *); diff --git a/statusbar.c b/statusbar.c index c92ee230c..5557b24ac 100644 --- a/statusbar.c +++ b/statusbar.c @@ -547,12 +547,12 @@ luaA_statusbar_new(lua_State *L) if(!(buf = luaA_getopt_string(L, 1, "fg", NULL)) || !xcolor_new(globalconf.connection, globalconf.default_screen, buf, &sb->colors.fg)) - sb->colors.fg = globalconf.colors.fg; + sb->colors.fg = xcolor_copy(&globalconf.colors.fg); if(!(buf = luaA_getopt_string(L, 1, "bg", NULL)) || !xcolor_new(globalconf.connection, globalconf.default_screen, buf, &sb->colors.bg)) - sb->colors.bg = globalconf.colors.bg; + sb->colors.bg = xcolor_copy(&globalconf.colors.bg); buf = luaA_getopt_lstring(L, 1, "align", "left", &len); sb->align = draw_align_fromstr(buf, len); diff --git a/titlebar.c b/titlebar.c index c9c6cdb5f..06b210e5c 100644 --- a/titlebar.c +++ b/titlebar.c @@ -317,17 +317,17 @@ luaA_titlebar_new(lua_State *L) if(!(buf = luaA_getopt_string(L, -1, "fg", NULL)) || !xcolor_new(globalconf.connection, globalconf.default_screen, buf, &tb->colors.fg)) - tb->colors.fg = globalconf.colors.fg; + tb->colors.fg = xcolor_copy(&globalconf.colors.fg); if(!(buf = luaA_getopt_string(L, -1, "bg", NULL)) || !xcolor_new(globalconf.connection, globalconf.default_screen, buf, &tb->colors.bg)) - tb->colors.bg = globalconf.colors.bg; + tb->colors.bg = xcolor_copy(&globalconf.colors.bg); if(!(buf = luaA_getopt_string(L, -1, "border_color", NULL)) || !xcolor_new(globalconf.connection, globalconf.default_screen, buf, &tb->border.color)) - tb->border.color = globalconf.colors.fg; + tb->border.color = xcolor_copy(&globalconf.colors.fg); tb->border.width = luaA_getopt_number(L, 1, "border_width", 0); diff --git a/widgets/graph.c b/widgets/graph.c index ee660d318..56c3d3ae6 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -124,7 +124,7 @@ graph_plot_add(graph_data_t *d, const char *title) plot->values = p_new(float, d->size); plot->lines = p_new(int, d->size); plot->max_value = 100.0; - plot->color_start = globalconf.colors.fg; + plot->color_start = xcolor_copy(&globalconf.colors.fg); plot->vertical_gradient = true; plot_list_append(&d->plots, plot); @@ -596,8 +596,8 @@ graph_new(alignment_t align) d->draw_from = p_new(int, d->size); d->draw_to = p_new(int, d->size); - d->bg = globalconf.colors.bg; - d->border_color = globalconf.colors.fg; + d->bg = xcolor_copy(&globalconf.colors.bg); + d->border_color = xcolor_copy(&globalconf.colors.fg); return w; } diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 159653f35..5c65505ed 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -103,10 +103,10 @@ progressbar_bar_add(progressbar_data_t *d, const char *title) bar_t *bar = p_new(bar_t, 1); bar->title = a_strdup(title); - bar->fg = globalconf.colors.fg; - bar->fg_off = globalconf.colors.bg; - bar->bg = globalconf.colors.bg; - bar->border_color = globalconf.colors.fg; + bar->fg = xcolor_copy(&globalconf.colors.fg); + bar->fg_off = xcolor_copy(&globalconf.colors.bg); + bar->bg = xcolor_copy(&globalconf.colors.bg); + bar->border_color = xcolor_copy(&globalconf.colors.fg); bar->max_value = 100.0; /* append the bar in the list */