diff --git a/CHANGELOG.md b/CHANGELOG.md index 15e555e..ba5abba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added +- Introduce new desktop-entry filter (#470) - Remove libxdg-basedir dependency (GLib's function is used instead) - `fullscreen` rule to hide notifications when a fullscreen window is active - When new notifications arrive, but display is full, important notifications don't diff --git a/src/dbus.c b/src/dbus.c index 0b5ea57..e4f098e 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -227,6 +227,11 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV g_variant_unref(dict_value); } + if ((dict_value = g_variant_lookup_value(hints, "desktop-entry", G_VARIANT_TYPE_STRING))) { + n->desktop_entry = g_variant_dup_string(dict_value, NULL); + g_variant_unref(dict_value); + } + if ((dict_value = g_variant_lookup_value(hints, "image-path", G_VARIANT_TYPE_STRING))) { g_free(n->iconname); n->iconname = g_variant_dup_string(dict_value, NULL); diff --git a/src/notification.c b/src/notification.c index f6e94f9..f1cc14d 100644 --- a/src/notification.c +++ b/src/notification.c @@ -56,6 +56,7 @@ void notification_print(const struct notification *n) printf("\ticon: '%s'\n", n->iconname); printf("\traw_icon set: %s\n", (n->icon_id && !STR_EQ(n->iconname, n->icon_id)) ? "true" : "false"); printf("\ticon_id: '%s'\n", n->icon_id); + printf("\tdesktop_entry: '%s'\n", n->desktop_entry ? n->desktop_entry : ""); printf("\tcategory: %s\n", n->category); printf("\ttimeout: %ld\n", n->timeout/1000); printf("\turgency: %s\n", notification_urgency_to_string(n->urgency)); @@ -225,6 +226,7 @@ void notification_unref(struct notification *n) g_free(n->colors.bg); g_free(n->colors.frame); g_free(n->stack_tag); + g_free(n->desktop_entry); g_hash_table_unref(n->actions); diff --git a/src/notification.h b/src/notification.h index f02f3b0..ad63d0b 100644 --- a/src/notification.h +++ b/src/notification.h @@ -45,6 +45,7 @@ struct notification { char *summary; char *body; char *category; + char *desktop_entry; /**< The desktop entry hint sent via every GApplication */ enum urgency urgency; GdkPixbuf *icon; /**< The raw cached icon data used to draw */ diff --git a/src/rules.c b/src/rules.c index fe9675d..10b0995 100644 --- a/src/rules.c +++ b/src/rules.c @@ -92,6 +92,7 @@ bool rule_matches_notification(struct rule *r, struct notification *n) return (r->msg_urgency == URG_NONE || r->msg_urgency == n->urgency) && (r->match_transient == -1 || (r->match_transient == n->transient)) && rule_field_matches_string(n->appname, r->appname) + && rule_field_matches_string(n->desktop_entry, r->desktop_entry) && rule_field_matches_string(n->summary, r->summary) && rule_field_matches_string(n->body, r->body) && rule_field_matches_string(n->iconname, r->icon) diff --git a/src/rules.h b/src/rules.h index 83f7b61..69e63a1 100644 --- a/src/rules.h +++ b/src/rules.h @@ -17,6 +17,7 @@ struct rule { char *icon; char *category; char *stack_tag; + char *desktop_entry; int msg_urgency; /* actions */ diff --git a/src/settings.c b/src/settings.c index fb70a36..9245b5f 100644 --- a/src/settings.c +++ b/src/settings.c @@ -724,6 +724,7 @@ void load_settings(char *cmdline_config_path) r->history_ignore = ini_get_bool(cur_section, "history_ignore", r->history_ignore); r->match_transient = ini_get_bool(cur_section, "match_transient", r->match_transient); r->set_transient = ini_get_bool(cur_section, "set_transient", r->set_transient); + r->desktop_entry = ini_get_string(cur_section, "desktop_entry", r->desktop_entry); { char *c = ini_get_string( cur_section, diff --git a/test/dbus.c b/test/dbus.c index 066a0d6..4987891 100644 --- a/test/dbus.c +++ b/test/dbus.c @@ -551,6 +551,39 @@ TEST test_hint_category(void) PASS(); } +TEST test_hint_desktop_entry(void) +{ + struct notification *n; + struct dbus_notification *n_dbus; + const char *desktop_entry = "org.dunst-project.dunst"; + + gsize len = queues_length_waiting(); + + n_dbus = dbus_notification_new(); + n_dbus->app_name = "dunstteststack"; + n_dbus->app_icon = "NONE"; + n_dbus->summary = "test_hint_desktopentry"; + n_dbus->body = "Summary of my desktop_entry"; + + g_hash_table_insert(n_dbus->hints, + g_strdup("desktop-entry"), + g_variant_ref_sink(g_variant_new_string(desktop_entry))); + + guint id; + ASSERT(dbus_notification_fire(n_dbus, &id)); + ASSERT(id != 0); + + ASSERT_EQ(queues_length_waiting(), len+1); + + n = queues_debug_find_notification_by_id(id); + + ASSERT_STR_EQ(desktop_entry, n->desktop_entry); + + dbus_notification_free(n_dbus); + + PASS(); +} + TEST test_hint_urgency(void) { static char msg[50]; @@ -779,6 +812,7 @@ gpointer run_threaded_tests(gpointer data) RUN_TEST(test_hint_progress); RUN_TEST(test_hint_icons); RUN_TEST(test_hint_category); + RUN_TEST(test_hint_desktop_entry); RUN_TEST(test_hint_urgency); RUN_TEST(test_hint_raw_image); RUN_TEST(test_dbus_notify_colors);