From 431c65fc768b99c4b01f5455e807cf444d6edd29 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Mar 2014 17:22:08 +0100 Subject: [PATCH] Add 'msg_urgency' as a new filter to match on the urgency. This patch adds a new filter 'msg_urgency' which _matches_ on the urgency on the notification. This allows to configure different notification parameters/scripts to different urgency levels. --- config.def.h | 14 +++++++------- dunstrc | 6 +++--- rules.c | 4 +++- rules.h | 1 + settings.c | 39 +++++++++++++++++++++++---------------- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/config.def.h b/config.def.h index 169683f..9f5c224 100644 --- a/config.def.h +++ b/config.def.h @@ -83,11 +83,11 @@ keyboard_shortcut context_ks = {.str = "none", rule_t default_rules[] = { /* name can be any unique string. It is used to identify the rule in dunstrc to override it there */ - /* name, appname, summary, body, icon, timeout, urgency, fg, bg, format, script */ - {"empty", NULL, NULL, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL}, - /* { "rule1", "notify-send", NULL, NULL, NULL, -1, -1, NULL, NULL, "%s %b", NULL }, */ - /* { "rule2", "Pidgin", "*says*, NULL, NULL, -1, CRITICAL, NULL, NULL, NULL, NULL }, */ - /* { "rule3", "Pidgin", "*signed on*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */ - /* { "rule4", "Pidgin", "*signed off*", NULL, NULL, -1, LOW, NULL, NULL, NULL, NULL }, */ - /* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, NULL, "#00FF00", NULL, NULL }, */ + /* name, appname, summary, body, icon, msg_urgency, timeout, urgency, fg, bg, format, script */ + { "empty", NULL, NULL, NULL, NULL, -1, -1, -1, NULL, NULL, NULL, NULL}, + /* { "rule1", "notify-send", NULL, NULL, NULL, -1, -1, -1, NULL, NULL, "%s %b", NULL }, */ + /* { "rule2", "Pidgin", "*says*, NULL, NULL, -1, -1, CRITICAL, NULL, NULL, NULL, NULL }, */ + /* { "rule3", "Pidgin", "*signed on*", NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */ + /* { "rule4", "Pidgin", "*signed off*", NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */ + /* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, -1, NULL, "#00FF00", NULL, NULL }, */ }; diff --git a/dunstrc b/dunstrc index c0a629d..bc72e46 100644 --- a/dunstrc +++ b/dunstrc @@ -183,9 +183,9 @@ # Every section that isn't one of the above is interpreted as a rules to # override settings for certain messages. -# Messages can be matched by "appname", "summary", "body" or "icon" and -# you can override the "timeout", "urgency", "foreground", "background" -# and "format". +# Messages can be matched by "appname", "summary", "body", "icon", +# "msg_urgency" and you can override the "timeout", "urgency", "foreground", +# "background" and "format". # Shell-like globbing will get expanded. # # SCRIPTING diff --git a/rules.c b/rules.c index 2b2478e..8cc5186 100644 --- a/rules.c +++ b/rules.c @@ -48,6 +48,7 @@ void rule_init(rule_t * r) r->summary = NULL; r->body = NULL; r->icon = NULL; + r->msg_urgency = -1; r->timeout = -1; r->urgency = -1; r->fg = NULL; @@ -64,6 +65,7 @@ bool rule_matches_notification(rule_t * r, notification * n) return ((!r->appname || !fnmatch(r->appname, n->appname, 0)) && (!r->summary || !fnmatch(r->summary, n->summary, 0)) && (!r->body || !fnmatch(r->body, n->body, 0)) - && (!r->icon || !fnmatch(r->icon, n->icon, 0))); + && (!r->icon || !fnmatch(r->icon, n->icon, 0)) + && (r->msg_urgency == -1 || r->msg_urgency == n->urgency)); } /* vim: set ts=8 sw=8 tw=0: */ diff --git a/rules.h b/rules.h index 92a46de..2862f75 100644 --- a/rules.h +++ b/rules.h @@ -13,6 +13,7 @@ typedef struct _rule_t { char *summary; char *body; char *icon; + int msg_urgency; /* actions */ int timeout; diff --git a/settings.c b/settings.c index 7b87d7a..ba97ec0 100644 --- a/settings.c +++ b/settings.c @@ -31,6 +31,27 @@ static void parse_follow_mode(const char *mode) } +static int ini_get_urgency(char *section, char *key, int def) +{ + int ret = def; + char *urg = ini_get_string(section, key, ""); + + if (strlen(urg) > 0) { + if (strcmp(urg, "low") == 0) + ret = LOW; + else if (strcmp(urg, "normal") == 0) + ret = NORM; + else if (strcmp(urg, "critical") == 0) + ret = CRIT; + else + fprintf(stderr, + "unknown urgency: %s, ignoring\n", + urg); + free(urg); + } + return ret; +} + void load_settings(char *cmdline_config_path) { @@ -291,22 +312,8 @@ void load_settings(char *cmdline_config_path) r->body = ini_get_string(cur_section, "body", r->body); r->icon = ini_get_string(cur_section, "icon", r->icon); r->timeout = ini_get_int(cur_section, "timeout", r->timeout); - { - char *urg = ini_get_string(cur_section, "urgency", ""); - if (strlen(urg) > 0) { - if (strcmp(urg, "low") == 0) - r->urgency = LOW; - else if (strcmp(urg, "normal") == 0) - r->urgency = NORM; - else if (strcmp(urg, "critical") == 0) - r->urgency = CRIT; - else - fprintf(stderr, - "unknown urgency: %s, ignoring\n", - urg); - free(urg); - } - } + r->urgency = ini_get_urgency(cur_section, "urgency", r->urgency); + r->msg_urgency = ini_get_urgency(cur_section, "msg_urgency", r->msg_urgency); r->fg = ini_get_string(cur_section, "foreground", r->fg); r->bg = ini_get_string(cur_section, "background", r->bg); r->format = ini_get_string(cur_section, "format", r->format);