From 585f0f85e0901c71b5a073fb1613793856193e76 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 23 Jul 2017 03:42:17 +0200 Subject: [PATCH] Add support for transistent hints --- CHANGELOG.md | 3 +++ docs/dunst.pod | 2 ++ dunstrc | 1 + src/dbus.c | 15 +++++++++++++++ src/dunst.c | 2 +- src/notification.c | 1 + src/notification.h | 1 + 7 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb97a72..737f387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Fixed - `new_icon` rule being ignored on notifications that had a raw icon +## Changed +- transient hints are now handled + ## 1.2.0 - 2017-07-12 ### Added diff --git a/docs/dunst.pod b/docs/dunst.pod index ee53aeb..b91df5e 100644 --- a/docs/dunst.pod +++ b/docs/dunst.pod @@ -234,6 +234,8 @@ Don't timeout notifications if user is idle longer than this value (in seconds). Set to 0 to disable. +Transient notifications will ignore this setting and timeout anyway. + =item B (default: "Monospace 8") Defines the font or font set used. Optionally set the size as a decimal number diff --git a/dunstrc b/dunstrc index 6faedc4..3b2857f 100644 --- a/dunstrc +++ b/dunstrc @@ -80,6 +80,7 @@ # Don't remove messages, if the user is idle (no mouse or keyboard input) # for longer than idle_threshold seconds. # Set to 0 to disable. + # Transient notifications ignore this setting. idle_threshold = 120 ### Text ### diff --git a/src/dbus.c b/src/dbus.c index 8efb2c0..27acc3c 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -138,6 +138,7 @@ static void on_notify(GDBusConnection * connection, /* hints */ gint urgency = 1; gint progress = -1; + gboolean transient = 0; gchar *fgcolor = NULL; gchar *bgcolor = NULL; gchar *category = NULL; @@ -202,6 +203,19 @@ static void on_notify(GDBusConnection * connection, if (dict_value) raw_icon = get_raw_image_from_data_hint(dict_value); + /* Check for transient hints + * + * According to the spec, the transient hint should be boolean. + * But notify-send does not support hints of type 'boolean'. + * So let's check for int and boolean until notify-send is fixed. + */ + if((dict_value = g_variant_lookup_value(content, "transient", G_VARIANT_TYPE_BOOLEAN))) + transient = g_variant_get_boolean(dict_value); + else if((dict_value = g_variant_lookup_value(content, "transient", G_VARIANT_TYPE_UINT32))) + transient = g_variant_get_uint32(dict_value) > 0; + else if((dict_value = g_variant_lookup_value(content, "transient", G_VARIANT_TYPE_INT32))) + transient = g_variant_get_int32(dict_value) > 0; + dict_value = g_variant_lookup_value(content, "value", G_VARIANT_TYPE_INT32); if (dict_value) { progress = g_variant_get_int32(dict_value); @@ -246,6 +260,7 @@ static void on_notify(GDBusConnection * connection, n->urgency = urgency; n->category = category; n->dbus_client = g_strdup(sender); + n->transient = transient; if (actions->count > 0) { n->actions = actions; } else { diff --git a/src/dunst.c b/src/dunst.c index d2893f9..83ad253 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -62,7 +62,7 @@ void check_timeouts(void) notification *n = iter->data; /* don't timeout when user is idle */ - if (x_is_idle()) { + if (x_is_idle() && !n->transient) { n->start = time(NULL); continue; } diff --git a/src/notification.c b/src/notification.c index df9e842..9a73958 100644 --- a/src/notification.c +++ b/src/notification.c @@ -41,6 +41,7 @@ void notification_print(notification * n) printf("\tcategory: %s\n", n->category); printf("\ttimeout: %d\n", n->timeout); printf("\turgency: %d\n", n->urgency); + printf("\ttransient: %d\n", n->transient); printf("\tformatted: '%s'\n", n->msg); printf("\tfg: %s\n", n->color_strings[ColFG]); printf("\tbg: %s\n", n->color_strings[ColBG]); diff --git a/src/notification.h b/src/notification.h index df64d08..59fb2cf 100644 --- a/src/notification.h +++ b/src/notification.h @@ -53,6 +53,7 @@ typedef struct _notification { int displayed_height; const char *color_strings[3]; bool first_render; + bool transient; int progress; /* percentage + 1, 0 to hide */ int line_count;