From 7d9b3689ac881b3c86fa38b16df75e0caff40363 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:06:55 +0100 Subject: [PATCH 1/3] Add more format options --- src/notification.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/notification.c b/src/notification.c index 6a0d4fe40..6e70138cf 100644 --- a/src/notification.c +++ b/src/notification.c @@ -566,6 +566,7 @@ static void notification_format_message(struct notification *n) g_clear_pointer(&n->msg, g_free); n->msg = string_replace_all("\\n", "\n", g_strdup(n->format)); + n->msg = string_replace_all("\\t", "\t", n->msg); /* replace all formatter */ for(char *substr = strchr(n->msg, '%'); @@ -597,6 +598,20 @@ static void notification_format_message(struct notification *n) n->body, n->markup); break; + case 'c': + notification_replace_single_field( + &n->msg, + &substr, + n->category, + MARKUP_NO); + break; + case 'U': + notification_replace_single_field( + &n->msg, + &substr, + notification_urgency_to_string(n->urgency), + MARKUP_NO); + break; case 'I': icon_tmp = g_strdup(n->iconname); notification_replace_single_field( From b8276edef3154c4e4ee446bcfcc3e81729f70612 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:09:54 +0100 Subject: [PATCH 2/3] Update docs --- docs/dunst.5.pod | 14 +++++++++----- dunstrc | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/dunst.5.pod b/docs/dunst.5.pod index ecac33d2a..67ee66ad3 100644 --- a/docs/dunst.5.pod +++ b/docs/dunst.5.pod @@ -148,7 +148,7 @@ Origin can be one of: center right-center -=item B format: (horizontal, vertical) +=item B (horizontal, vertical) Respectively the horizontal and vertical offset in pixels from the corner of the screen specified by B. A negative offset will lead to the @@ -395,10 +395,10 @@ the notification window. Regardless of the status of the B setting, any markup tags that are present in the format will be parsed. Note that because of that, if a literal -ampersand (&) is needed it needs to be escaped as '&' +ampersand (&) is needed it needs to be escaped as '&'. -If '\n' is present anywhere in the format, it will be replaced with -a literal newline. +If '\n' or '\t' is present anywhere in the format, it will be replaced with +a literal newline or tab respectively. If any of the following strings are present, they will be replaced with the equivalent notification attribute. @@ -414,6 +414,10 @@ For a complete markup reference, see =item B<%b> body +=item B<%c> category + +=item B<%U> urgency (LOW, NORMAL, CRITICAL) + =item B<%i> iconname (including its path) =item B<%I> iconname (without its path) @@ -422,7 +426,7 @@ For a complete markup reference, see =item B<%n> progress value without any extra characters -=item B<%%> Literal % +=item B<%%> literal % =back diff --git a/dunstrc b/dunstrc index 7903ff80e..64e2cc5df 100644 --- a/dunstrc +++ b/dunstrc @@ -178,6 +178,8 @@ # %a appname # %s summary # %b body + # %c category + # %U urgency (LOW, NORMAL, CRITICAL) # %i iconname (including its path) # %I iconname (without its path) # %p progress value if set ([ 0%] to [100%]) or nothing From 3485268cf6cd3326426041b588b2e809bc8b9d96 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:14:39 +0100 Subject: [PATCH 3/3] Update test --- test/notification.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/notification.c b/test/notification.c index 7f0330164..295ac8842 100644 --- a/test/notification.c +++ b/test/notification.c @@ -264,23 +264,26 @@ SUITE(suite_notification) // TEST notification_format_message struct notification *a = notification_create(); - a->appname = g_strdup("MyApp"); - a->summary = g_strdup("I've got a summary!"); - a->body = g_strdup("Look at my shiny "); - a->iconname = g_strdup("/this/is/my/icoknpath.png"); + a->appname = g_strdup("MyApp"); + a->summary = g_strdup("I've got a summary!"); + a->body = g_strdup("Look at my shiny "); + a->category = g_strdup("This category"); + a->iconname = g_strdup("/this/is/my/icoknpath.png"); a->progress = 95; const char *strings[] = { "%a", "MyApp", "%s", "I've got a summary!", "%b", "Look at my shiny ", + "%c", "This category", + "%U", "NORMAL", "%I", "icoknpath.png", "%i", "/this/is/my/icoknpath.png", "%p", "[ 95%]", "%n", "95", "%%", "%", "%", "%", - "%UNKNOWN", "%UNKNOWN", + "%WHATEVER", "%WHATEVER", NULL };