From 3828cca699c708c7cc386d6434d196e42057dcb8 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 23 Jan 2019 16:17:32 +0100 Subject: [PATCH] Introduce rule_new --- src/rules.c | 22 +++++----------------- src/rules.h | 8 +++++++- src/settings.c | 3 +-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/rules.c b/src/rules.c index b27419a..fe9675d 100644 --- a/src/rules.c +++ b/src/rules.c @@ -63,32 +63,20 @@ void rule_apply_all(struct notification *n) } } -/* - * Initialize rule with default values. - */ -void rule_init(struct rule *r) +struct rule *rule_new(void) { - r->name = NULL; - r->appname = NULL; - r->summary = NULL; - r->body = NULL; - r->icon = NULL; - r->category = NULL; - r->stack_tag = NULL; + struct rule *r = g_malloc0(sizeof(struct rule)); + r->msg_urgency = URG_NONE; r->timeout = -1; r->urgency = URG_NONE; r->fullscreen = FS_NULL; r->markup = MARKUP_NULL; - r->new_icon = NULL; r->history_ignore = false; r->match_transient = -1; r->set_transient = -1; - r->fg = NULL; - r->bg = NULL; - r->fc = NULL; - r->format = NULL; - r->set_stack_tag = NULL; + + return r; } static inline bool rule_field_matches_string(const char *value, const char *pattern) diff --git a/src/rules.h b/src/rules.h index df45f5d..83f7b61 100644 --- a/src/rules.h +++ b/src/rules.h @@ -38,7 +38,13 @@ struct rule { extern GSList *rules; -void rule_init(struct rule *r); +/** + * Allocate a new rule. The rule is fully initialised. + * + * @returns A new initialised rule. + */ +struct rule *rule_new(void); + void rule_apply(struct rule *r, struct notification *n); void rule_apply_all(struct notification *n); bool rule_matches_notification(struct rule *r, struct notification *n); diff --git a/src/settings.c b/src/settings.c index 2f6a7b5..fb70a36 100644 --- a/src/settings.c +++ b/src/settings.c @@ -688,8 +688,7 @@ void load_settings(char *cmdline_config_path) } if (!r) { - r = g_malloc(sizeof(struct rule)); - rule_init(r); + r = rule_new(); rules = g_slist_insert(rules, r, -1); }