Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format options "%c" "%U" #1430

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/dunst.5.pod
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Origin can be one of:
center
right-center

=item B<offset> format: (horizontal, vertical)
=item B<offset> (horizontal, vertical)

Respectively the horizontal and vertical offset in pixels from the corner
of the screen specified by B<origin>. A negative offset will lead to the
Expand Down Expand Up @@ -395,10 +395,10 @@ the notification window.

Regardless of the status of the B<markup> 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 '&amp;'
ampersand (&) is needed it needs to be escaped as '&amp;'.

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.
Expand All @@ -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)
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions dunstrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, '%');
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 8 additions & 5 deletions test/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <notification>");
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 <notification>");
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&apos;ve got a summary!",
"%b", "Look at my shiny <notification>",
"%c", "This category",
"%U", "NORMAL",
"%I", "icoknpath.png",
"%i", "/this/is/my/icoknpath.png",
"%p", "[ 95%]",
"%n", "95",
"%%", "%",
"%", "%",
"%UNKNOWN", "%UNKNOWN",
"%WHATEVER", "%WHATEVER",
NULL
};

Expand Down
Loading