Add support for desktop-entry hints

This commit is contained in:
Benedikt Heine 2019-01-23 16:41:07 +01:00
parent 3828cca699
commit 1e82c761c9
8 changed files with 46 additions and 0 deletions

View File

@ -4,6 +4,7 @@
### Added ### Added
- Introduce new desktop-entry filter (#470)
- Remove libxdg-basedir dependency (GLib's function is used instead) - Remove libxdg-basedir dependency (GLib's function is used instead)
- `fullscreen` rule to hide notifications when a fullscreen window is active - `fullscreen` rule to hide notifications when a fullscreen window is active
- When new notifications arrive, but display is full, important notifications don't - When new notifications arrive, but display is full, important notifications don't

View File

@ -227,6 +227,11 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
g_variant_unref(dict_value); 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))) { if ((dict_value = g_variant_lookup_value(hints, "image-path", G_VARIANT_TYPE_STRING))) {
g_free(n->iconname); g_free(n->iconname);
n->iconname = g_variant_dup_string(dict_value, NULL); n->iconname = g_variant_dup_string(dict_value, NULL);

View File

@ -56,6 +56,7 @@ void notification_print(const struct notification *n)
printf("\ticon: '%s'\n", n->iconname); 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("\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("\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("\tcategory: %s\n", n->category);
printf("\ttimeout: %ld\n", n->timeout/1000); printf("\ttimeout: %ld\n", n->timeout/1000);
printf("\turgency: %s\n", notification_urgency_to_string(n->urgency)); 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.bg);
g_free(n->colors.frame); g_free(n->colors.frame);
g_free(n->stack_tag); g_free(n->stack_tag);
g_free(n->desktop_entry);
g_hash_table_unref(n->actions); g_hash_table_unref(n->actions);

View File

@ -45,6 +45,7 @@ struct notification {
char *summary; char *summary;
char *body; char *body;
char *category; char *category;
char *desktop_entry; /**< The desktop entry hint sent via every GApplication */
enum urgency urgency; enum urgency urgency;
GdkPixbuf *icon; /**< The raw cached icon data used to draw */ GdkPixbuf *icon; /**< The raw cached icon data used to draw */

View File

@ -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) return (r->msg_urgency == URG_NONE || r->msg_urgency == n->urgency)
&& (r->match_transient == -1 || (r->match_transient == n->transient)) && (r->match_transient == -1 || (r->match_transient == n->transient))
&& rule_field_matches_string(n->appname, r->appname) && 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->summary, r->summary)
&& rule_field_matches_string(n->body, r->body) && rule_field_matches_string(n->body, r->body)
&& rule_field_matches_string(n->iconname, r->icon) && rule_field_matches_string(n->iconname, r->icon)

View File

@ -17,6 +17,7 @@ struct rule {
char *icon; char *icon;
char *category; char *category;
char *stack_tag; char *stack_tag;
char *desktop_entry;
int msg_urgency; int msg_urgency;
/* actions */ /* actions */

View File

@ -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->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->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->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( char *c = ini_get_string(
cur_section, cur_section,

View File

@ -551,6 +551,39 @@ TEST test_hint_category(void)
PASS(); 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) TEST test_hint_urgency(void)
{ {
static char msg[50]; static char msg[50];
@ -779,6 +812,7 @@ gpointer run_threaded_tests(gpointer data)
RUN_TEST(test_hint_progress); RUN_TEST(test_hint_progress);
RUN_TEST(test_hint_icons); RUN_TEST(test_hint_icons);
RUN_TEST(test_hint_category); RUN_TEST(test_hint_category);
RUN_TEST(test_hint_desktop_entry);
RUN_TEST(test_hint_urgency); RUN_TEST(test_hint_urgency);
RUN_TEST(test_hint_raw_image); RUN_TEST(test_hint_raw_image);
RUN_TEST(test_dbus_notify_colors); RUN_TEST(test_dbus_notify_colors);