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); dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING);
if (dict_value) { 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); g_variant_unref(dict_value);
} }
dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING); dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING);
if (dict_value) { 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); g_variant_unref(dict_value);
} }
dict_value = g_variant_lookup_value(content, "frcolor", G_VARIANT_TYPE_STRING); dict_value = g_variant_lookup_value(content, "frcolor", G_VARIANT_TYPE_STRING);
if (dict_value) { 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); 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->icon = NULL;
} }
cl->fg = string_to_color(n->colors[ColFG]); cl->fg = string_to_color(n->colors.fg);
cl->bg = string_to_color(n->colors[ColBG]); cl->bg = string_to_color(n->colors.bg);
cl->frame = string_to_color(n->colors[ColFrame]); cl->frame = string_to_color(n->colors.frame);
cl->n = n; 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("\turgency: %s\n", notification_urgency_to_string(n->urgency));
printf("\ttransient: %d\n", n->transient); printf("\ttransient: %d\n", n->transient);
printf("\tformatted: '%s'\n", n->msg); printf("\tformatted: '%s'\n", n->msg);
printf("\tfg: %s\n", n->colors[ColFG]); printf("\tfg: %s\n", n->colors.fg);
printf("\tbg: %s\n", n->colors[ColBG]); printf("\tbg: %s\n", n->colors.bg);
printf("\tframe: %s\n", n->colors[ColFrame]); printf("\tframe: %s\n", n->colors.frame);
printf("\tfullscreen: %s\n", enum_to_string_fullscreen(n->fullscreen)); printf("\tfullscreen: %s\n", enum_to_string_fullscreen(n->fullscreen));
printf("\tprogress: %d\n", n->progress); printf("\tprogress: %d\n", n->progress);
printf("\tstack_tag: %s\n", (n->stack_tag ? n->stack_tag : "")); 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->category);
g_free(n->text_to_render); g_free(n->text_to_render);
g_free(n->urls); g_free(n->urls);
g_free(n->colors[ColFG]); g_free(n->colors.fg);
g_free(n->colors[ColBG]); g_free(n->colors.bg);
g_free(n->colors[ColFrame]); g_free(n->colors.frame);
g_free(n->stack_tag); g_free(n->stack_tag);
actions_free(n->actions); actions_free(n->actions);
@ -348,12 +348,12 @@ void notification_init(struct notification *n)
n->icon = g_strdup(settings.icons[n->urgency]); n->icon = g_strdup(settings.icons[n->urgency]);
/* Color hints */ /* Color hints */
if (!n->colors[ColFG]) if (!n->colors.fg)
n->colors[ColFG] = g_strdup(xctx.colors[ColFG][n->urgency]); n->colors.fg = g_strdup(xctx.colors[ColFG][n->urgency]);
if (!n->colors[ColBG]) if (!n->colors.bg)
n->colors[ColBG] = g_strdup(xctx.colors[ColBG][n->urgency]); n->colors.bg = g_strdup(xctx.colors[ColBG][n->urgency]);
if (!n->colors[ColFrame]) if (!n->colors.frame)
n->colors[ColFrame] = g_strdup(xctx.colors[ColFrame][n->urgency]); n->colors.frame = g_strdup(xctx.colors[ColFrame][n->urgency]);
/* Sanitize misc hints */ /* Sanitize misc hints */
if (n->progress < 0) if (n->progress < 0)

View File

@ -44,6 +44,12 @@ struct actions {
typedef struct _notification_private NotificationPrivate; typedef struct _notification_private NotificationPrivate;
struct notification_colors {
char *frame;
char *bg;
char *fg;
};
struct notification { struct notification {
NotificationPrivate *priv; NotificationPrivate *priv;
int id; int id;
@ -68,7 +74,7 @@ struct notification {
enum markup_mode markup; enum markup_mode markup;
const char *format; const char *format;
const char *script; const char *script;
char *colors[3]; struct notification_colors colors;
char *stack_tag; /**< stack notifications by tag */ 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); g_clear_pointer(&n->raw_icon, rawimage_free);
} }
if (r->fg) { if (r->fg) {
g_free(n->colors[ColFG]); g_free(n->colors.fg);
n->colors[ColFG] = g_strdup(r->fg); n->colors.fg = g_strdup(r->fg);
} }
if (r->bg) { if (r->bg) {
g_free(n->colors[ColBG]); g_free(n->colors.bg);
n->colors[ColBG] = g_strdup(r->bg); n->colors.bg = g_strdup(r->bg);
} }
if (r->fc) { if (r->fc) {
g_free(n->colors[ColFrame]); g_free(n->colors.frame);
n->colors[ColFrame] = g_strdup(r->fc); n->colors.frame = g_strdup(r->fc);
} }
if (r->format) if (r->format)
n->format = r->format; n->format = r->format;