Merge branch 'match_msg_urgency' of git://github.com/wavexx/dunst into pull_requests

This commit is contained in:
Sascha Kruse 2014-03-08 11:35:11 +01:00
commit 54c1b58cb0
5 changed files with 37 additions and 27 deletions

View File

@ -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 }, */
};

View File

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

View File

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

View File

@ -13,6 +13,7 @@ typedef struct _rule_t {
char *summary;
char *body;
char *icon;
int msg_urgency;
/* actions */
int timeout;

View File

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