Skip to content

Commit 8a4af74

Browse files
authored
Merge pull request #1430 from bynect/add-format
Add format options "%c" "%S"
2 parents 87d656d + c18dcb5 commit 8a4af74

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

docs/dunst.5.pod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ the notification window.
397397

398398
Regardless of the status of the B<markup> setting, any markup tags that are
399399
present in the format will be parsed. Note that because of that, if a literal
400-
ampersand (&) is needed it needs to be escaped as '&amp;'
400+
ampersand (&) is needed it needs to be escaped as '&amp;'.
401401

402-
If '\n' is present anywhere in the format, it will be replaced with
403-
a literal newline.
402+
If '\n' or '\t' is present anywhere in the format, it will be replaced with
403+
a literal newline or tab respectively.
404404

405405
If any of the following strings are present, they will be replaced with the
406406
equivalent notification attribute.
@@ -416,6 +416,10 @@ For a complete markup reference, see
416416

417417
=item B<%b> body
418418

419+
=item B<%c> category
420+
421+
=item B<%S> stack_tag
422+
419423
=item B<%i> iconname (including its path)
420424

421425
=item B<%I> iconname (without its path)

dunstrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@
178178
# %a appname
179179
# %s summary
180180
# %b body
181+
# %c category
182+
# %U urgency (LOW, NORMAL, CRITICAL)
181183
# %i iconname (including its path)
182184
# %I iconname (without its path)
183185
# %p progress value if set ([ 0%] to [100%]) or nothing

src/notification.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ static void notification_format_message(struct notification *n)
566566
g_clear_pointer(&n->msg, g_free);
567567

568568
n->msg = string_replace_all("\\n", "\n", g_strdup(n->format));
569+
n->msg = string_replace_all("\\t", "\t", n->msg);
569570

570571
/* replace all formatter */
571572
for(char *substr = strchr(n->msg, '%');
@@ -597,6 +598,20 @@ static void notification_format_message(struct notification *n)
597598
n->body,
598599
n->markup);
599600
break;
601+
case 'c':
602+
notification_replace_single_field(
603+
&n->msg,
604+
&substr,
605+
n->category,
606+
MARKUP_NO);
607+
break;
608+
case 'S':
609+
notification_replace_single_field(
610+
&n->msg,
611+
&substr,
612+
n->stack_tag,
613+
MARKUP_NO);
614+
break;
600615
case 'I':
601616
icon_tmp = g_strdup(n->iconname);
602617
notification_replace_single_field(

test/notification.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,23 +264,27 @@ SUITE(suite_notification)
264264

265265
// TEST notification_format_message
266266
struct notification *a = notification_create();
267-
a->appname = g_strdup("MyApp");
268-
a->summary = g_strdup("I've got a summary!");
269-
a->body = g_strdup("Look at my shiny <notification>");
270-
a->iconname = g_strdup("/this/is/my/icoknpath.png");
267+
a->appname = g_strdup("MyApp");
268+
a->summary = g_strdup("I've got a summary!");
269+
a->body = g_strdup("Look at my shiny <notification>");
270+
a->category = g_strdup("This category");
271+
a->iconname = g_strdup("/this/is/my/icoknpath.png");
272+
a->stack_tag = g_strdup("test");
271273
a->progress = 95;
272274

273275
const char *strings[] = {
274276
"%a", "MyApp",
275277
"%s", "I&apos;ve got a summary!",
276278
"%b", "Look at my shiny <notification>",
279+
"%c", "This category",
280+
"%S", "test",
277281
"%I", "icoknpath.png",
278282
"%i", "/this/is/my/icoknpath.png",
279283
"%p", "[ 95%]",
280284
"%n", "95",
281285
"%%", "%",
282286
"%", "%",
283-
"%UNKNOWN", "%UNKNOWN",
287+
"%WHATEVER", "%WHATEVER",
284288
NULL
285289
};
286290

0 commit comments

Comments
 (0)