From 35cb023915d2d53913b155f911458c1ad7bd6ea7 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Mon, 18 Jun 2012 16:10:20 +0200 Subject: [PATCH] trim message assuming a format like "%s %b" and the body is empty, the notification ends with a space, leading to not centered text in the window. --- dunst.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dunst.c b/dunst.c index 138975a..fb44b33 100644 --- a/dunst.c +++ b/dunst.c @@ -102,6 +102,7 @@ void initmsg(msg_queue_t *msg); rule_t *initrule(void); int is_idle(void); char *string_replace(const char *needle, const char *replacement, char *haystack); +char *strtrim(char *str); void run(void); void setup(void); void show_win(void); @@ -558,6 +559,7 @@ initmsg(msg_queue_t *msg) { msg->msg = string_replace("%b", msg->body, msg->msg); msg->msg = fix_markup(msg->msg); + msg->msg = strtrim(msg->msg); /* urgency > CRIT -> array out of range */ msg->urgency = msg->urgency > CRIT ? CRIT : msg->urgency; @@ -641,6 +643,21 @@ string_replace(const char *needle, const char *replacement, char *haystack) { } } +char * +strtrim(char *str) { + char *end; + while(isspace(*str)) str++; + + end = str + strlen(str) - 1; + while(isspace(*end)) { + *end = '\0'; + end--; + } + + return str; + +} + void run(void) {