Introduce rule_new

This commit is contained in:
Benedikt Heine 2019-01-23 16:17:32 +01:00
parent 53ad430b48
commit 3828cca699
3 changed files with 13 additions and 20 deletions

View File

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

View File

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

View File

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