From c3cd623f414a49518897d8c04939921ce62162e3 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 12 Jan 2018 18:15:22 +0100 Subject: [PATCH] Use notification_colors struct for notification colors --- src/dbus.c | 6 +++--- src/draw.c | 6 +++--- src/notification.c | 24 ++++++++++++------------ src/notification.h | 8 +++++++- src/rules.c | 12 ++++++------ 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 41fbddc..bc07096 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -192,19 +192,19 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING); if (dict_value) { - n->colors[ColFG] = g_variant_dup_string(dict_value, NULL); + n->colors.fg = g_variant_dup_string(dict_value, NULL); g_variant_unref(dict_value); } dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING); if (dict_value) { - n->colors[ColBG] = g_variant_dup_string(dict_value, NULL); + n->colors.bg = g_variant_dup_string(dict_value, NULL); g_variant_unref(dict_value); } dict_value = g_variant_lookup_value(content, "frcolor", G_VARIANT_TYPE_STRING); if (dict_value) { - n->colors[ColFrame] = g_variant_dup_string(dict_value, NULL); + n->colors.frame = g_variant_dup_string(dict_value, NULL); g_variant_unref(dict_value); } diff --git a/src/draw.c b/src/draw.c index cf51ae1..5e50e0b 100644 --- a/src/draw.c +++ b/src/draw.c @@ -281,9 +281,9 @@ static struct colored_layout *layout_init_shared(cairo_t *c, const struct notifi cl->icon = NULL; } - cl->fg = string_to_color(n->colors[ColFG]); - cl->bg = string_to_color(n->colors[ColBG]); - cl->frame = string_to_color(n->colors[ColFrame]); + cl->fg = string_to_color(n->colors.fg); + cl->bg = string_to_color(n->colors.bg); + cl->frame = string_to_color(n->colors.frame); cl->n = n; diff --git a/src/notification.c b/src/notification.c index fabda53..66d9b3b 100644 --- a/src/notification.c +++ b/src/notification.c @@ -61,9 +61,9 @@ void notification_print(const struct notification *n) printf("\turgency: %s\n", notification_urgency_to_string(n->urgency)); printf("\ttransient: %d\n", n->transient); printf("\tformatted: '%s'\n", n->msg); - printf("\tfg: %s\n", n->colors[ColFG]); - printf("\tbg: %s\n", n->colors[ColBG]); - printf("\tframe: %s\n", n->colors[ColFrame]); + printf("\tfg: %s\n", n->colors.fg); + printf("\tbg: %s\n", n->colors.bg); + printf("\tframe: %s\n", n->colors.frame); printf("\tfullscreen: %s\n", enum_to_string_fullscreen(n->fullscreen)); printf("\tprogress: %d\n", n->progress); printf("\tstack_tag: %s\n", (n->stack_tag ? n->stack_tag : "")); @@ -249,9 +249,9 @@ void notification_unref(struct notification *n) g_free(n->category); g_free(n->text_to_render); g_free(n->urls); - g_free(n->colors[ColFG]); - g_free(n->colors[ColBG]); - g_free(n->colors[ColFrame]); + g_free(n->colors.fg); + g_free(n->colors.bg); + g_free(n->colors.frame); g_free(n->stack_tag); actions_free(n->actions); @@ -348,12 +348,12 @@ void notification_init(struct notification *n) n->icon = g_strdup(settings.icons[n->urgency]); /* Color hints */ - if (!n->colors[ColFG]) - n->colors[ColFG] = g_strdup(xctx.colors[ColFG][n->urgency]); - if (!n->colors[ColBG]) - n->colors[ColBG] = g_strdup(xctx.colors[ColBG][n->urgency]); - if (!n->colors[ColFrame]) - n->colors[ColFrame] = g_strdup(xctx.colors[ColFrame][n->urgency]); + if (!n->colors.fg) + n->colors.fg = g_strdup(xctx.colors[ColFG][n->urgency]); + if (!n->colors.bg) + n->colors.bg = g_strdup(xctx.colors[ColBG][n->urgency]); + if (!n->colors.frame) + n->colors.frame = g_strdup(xctx.colors[ColFrame][n->urgency]); /* Sanitize misc hints */ if (n->progress < 0) diff --git a/src/notification.h b/src/notification.h index 185232d..de18926 100644 --- a/src/notification.h +++ b/src/notification.h @@ -44,6 +44,12 @@ struct actions { typedef struct _notification_private NotificationPrivate; +struct notification_colors { + char *frame; + char *bg; + char *fg; +}; + struct notification { NotificationPrivate *priv; int id; @@ -68,7 +74,7 @@ struct notification { enum markup_mode markup; const char *format; const char *script; - char *colors[3]; + struct notification_colors colors; char *stack_tag; /**< stack notifications by tag */ diff --git a/src/rules.c b/src/rules.c index 104b4f2..d23c580 100644 --- a/src/rules.c +++ b/src/rules.c @@ -32,16 +32,16 @@ void rule_apply(struct rule *r, struct notification *n) g_clear_pointer(&n->raw_icon, rawimage_free); } if (r->fg) { - g_free(n->colors[ColFG]); - n->colors[ColFG] = g_strdup(r->fg); + g_free(n->colors.fg); + n->colors.fg = g_strdup(r->fg); } if (r->bg) { - g_free(n->colors[ColBG]); - n->colors[ColBG] = g_strdup(r->bg); + g_free(n->colors.bg); + n->colors.bg = g_strdup(r->bg); } if (r->fc) { - g_free(n->colors[ColFrame]); - n->colors[ColFrame] = g_strdup(r->fc); + g_free(n->colors.frame); + n->colors.frame = g_strdup(r->fc); } if (r->format) n->format = r->format;