Use notification_colors struct for notification colors

This commit is contained in:
Benedikt Heine 2018-01-12 18:15:22 +01:00
parent 7b1157c5af
commit c3cd623f41
5 changed files with 31 additions and 25 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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)

View File

@ -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 */

View File

@ -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;