From 1ccb6185ac04a37e59fa3ddb28d8c83759cd1d55 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Sat, 8 Mar 2014 15:03:38 +0100 Subject: [PATCH] allow rule matching against category fix issue #135 --- config.def.h | 14 +++++++------- dbus.c | 13 +++++++++++++ dunst.c | 1 + dunstrc | 2 +- notification.c | 5 +++++ notification.h | 1 + rules.c | 2 ++ rules.h | 1 + 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/config.def.h b/config.def.h index 4df3438..e3d00c5 100644 --- a/config.def.h +++ b/config.def.h @@ -87,11 +87,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, 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 }, */ + /* name, appname, summary, body, icon, category, msg_urgency, timeout, urgency, fg, bg, format, script */ + { "empty", NULL, NULL, NULL, NULL, NULL, -1, -1, -1, NULL, NULL, NULL, NULL}, + /* { "rule1", "notify-send", NULL, NULL, NULL, NULL, -1, -1, -1, NULL, NULL, "%s %b", NULL }, */ + /* { "rule2", "Pidgin", "*says*, NULL, NULL, NULL, -1, -1, CRITICAL, NULL, NULL, NULL, NULL }, */ + /* { "rule3", "Pidgin", "*signed on*", NULL, NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */ + /* { "rule4", "Pidgin", "*signed off*", NULL, NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */ + /* { "rule5", NULL, "*foobar*", NULL, NULL, NULL, -1, -1, -1, NULL, "#00FF00", NULL, NULL }, */ }; diff --git a/dbus.c b/dbus.c index 729cab1..13edfcc 100644 --- a/dbus.c +++ b/dbus.c @@ -131,6 +131,7 @@ static void onNotify(GDBusConnection * connection, gint progress = -1; gchar *fgcolor = NULL; gchar *bgcolor = NULL; + gchar *category = NULL; actions->actions = NULL; actions->count = 0; @@ -212,6 +213,17 @@ static void onNotify(GDBusConnection * connection, g_variant_dup_string (dict_value, NULL); + dict_value = + g_variant_lookup_value(content, + "category", + G_VARIANT_TYPE_STRING); + + if (dict_value) { + category = + g_variant_dup_string( + dict_value, NULL); + } + dict_value = g_variant_lookup_value(content, "value", @@ -263,6 +275,7 @@ static void onNotify(GDBusConnection * connection, n->timeout = timeout; n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1; n->urgency = urgency; + n->category = category; n->dbus_client = strdup(sender); if (actions->count > 0) { n->actions = actions; diff --git a/dunst.c b/dunst.c index f8f0784..0fc1d9e 100644 --- a/dunst.c +++ b/dunst.c @@ -305,6 +305,7 @@ int main(int argc, char *argv[]) n->timeout = 10; n->urgency = LOW; n->icon = NULL; + n->category = NULL; n->msg = NULL; n->dbus_client = NULL; n->color_strings[0] = NULL; diff --git a/dunstrc b/dunstrc index 03688f3..d6606a0 100644 --- a/dunstrc +++ b/dunstrc @@ -189,7 +189,7 @@ # 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", "icon", +# Messages can be matched by "appname", "summary", "body", "icon", "category", # "msg_urgency" and you can override the "timeout", "urgency", "foreground", # "background", "new_icon" and "format". # Shell-like globbing will get expanded. diff --git a/notification.c b/notification.c index 3510851..5e0a82f 100644 --- a/notification.c +++ b/notification.c @@ -32,6 +32,7 @@ void notification_print(notification * n) printf("\tsummary: '%s'\n", n->summary); printf("\tbody: '%s'\n", n->body); printf("\ticon: '%s'\n", n->icon); + printf("\tcategory: %s\n", n->category); printf("\turgency: %d\n", n->urgency); printf("\tformatted: '%s'\n", n->msg); printf("\tfg: %s\n", n->color_strings[ColFG]); @@ -391,6 +392,10 @@ int notification_init(notification * n, int id) n->icon = settings.icons[n->urgency]; } + if (n->category == NULL) { + n->category = ""; + } + n->timestamp = time(NULL); n->redisplayed = false; diff --git a/notification.h b/notification.h index 75961ef..38a4e04 100644 --- a/notification.h +++ b/notification.h @@ -19,6 +19,7 @@ typedef struct _notification { char *body; char *icon; char *msg; /* formatted message */ + char *category; char *text_to_render; const char *format; char *dbus_client; diff --git a/rules.c b/rules.c index 4762c9f..6934601 100644 --- a/rules.c +++ b/rules.c @@ -50,6 +50,7 @@ void rule_init(rule_t * r) r->summary = NULL; r->body = NULL; r->icon = NULL; + r->category = NULL; r->msg_urgency = -1; r->timeout = -1; r->urgency = -1; @@ -69,6 +70,7 @@ bool rule_matches_notification(rule_t * r, notification * n) && (!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->category || !fnmatch(r->category, n->category, 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 397dd64..71796c6 100644 --- a/rules.h +++ b/rules.h @@ -13,6 +13,7 @@ typedef struct _rule_t { char *summary; char *body; char *icon; + char *category; int msg_urgency; /* actions */