From bf6c1a6406ad28899dec11504e3de87125e526d6 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Wed, 22 Jan 2014 10:41:42 +0100 Subject: [PATCH] make notification stacking optional see #137 --- dunstrc | 3 ++ notification.c | 90 ++++++++++++++++++++++++++------------------------ settings.c | 3 ++ settings.h | 1 + 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/dunstrc b/dunstrc index 6825341..8c8c8f3 100644 --- a/dunstrc +++ b/dunstrc @@ -27,6 +27,9 @@ # Show how many messages are currently hidden (because of geometry) indicate_hidden = yes + # Stack duplicate Messages or show them individually + stack_duplicates = yes + # alignment of message text. # Possible values are "left", "center" and "right" alignment = left diff --git a/notification.c b/notification.c index 0156970..42242d6 100644 --- a/notification.c +++ b/notification.c @@ -315,54 +315,56 @@ int notification_init(notification * n, int id) n->dup_count = 0; /* check if n is a duplicate */ - for (GList * iter = g_queue_peek_head_link(queue); iter; - iter = iter->next) { - notification *orig = iter->data; - if (strcmp(orig->appname, n->appname) == 0 - && strcmp(orig->summary, n->summary) == 0 - && strcmp(orig->body, n->body) == 0) { - /* If the progress differs this was probably intended to replace the notification - * but notify-send was used. So don't increment dup_count in this case - */ - if (orig->progress == n->progress) { - orig->dup_count++; - } else { - orig->progress = n->progress; + if (settings.stack_duplicates) { + for (GList * iter = g_queue_peek_head_link(queue); iter; + iter = iter->next) { + notification *orig = iter->data; + if (strcmp(orig->appname, n->appname) == 0 + && strcmp(orig->summary, n->summary) == 0 + && strcmp(orig->body, n->body) == 0) { + /* If the progress differs this was probably intended to replace the notification + * but notify-send was used. So don't increment dup_count in this case + */ + if (orig->progress == n->progress) { + orig->dup_count++; + } else { + orig->progress = n->progress; + } + /* notifications that differ only in progress hints should be expected equal, + * but we want the latest message, with the latest hint value + */ + free(orig->msg); + orig->msg = strdup(n->msg); + notification_free(n); + wake_up(); + return orig->id; } - /* notifications that differ only in progress hints should be expected equal, - * but we want the latest message, with the latest hint value - */ - free(orig->msg); - orig->msg = strdup(n->msg); - notification_free(n); - wake_up(); - return orig->id; } - } - for (GList * iter = g_queue_peek_head_link(displayed); iter; - iter = iter->next) { - notification *orig = iter->data; - if (strcmp(orig->appname, n->appname) == 0 - && strcmp(orig->summary, n->summary) == 0 - && strcmp(orig->body, n->body) == 0) { - /* notifications that differ only in progress hints should be expected equal, - * but we want the latest message, with the latest hint value - */ - free(orig->msg); - orig->msg = strdup(n->msg); - /* If the progress differs this was probably intended to replace the notification - * but notify-send was used. So don't increment dup_count in this case - */ - if (orig->progress == n->progress) { - orig->dup_count++; - } else { - orig->progress = n->progress; + for (GList * iter = g_queue_peek_head_link(displayed); iter; + iter = iter->next) { + notification *orig = iter->data; + if (strcmp(orig->appname, n->appname) == 0 + && strcmp(orig->summary, n->summary) == 0 + && strcmp(orig->body, n->body) == 0) { + /* notifications that differ only in progress hints should be expected equal, + * but we want the latest message, with the latest hint value + */ + free(orig->msg); + orig->msg = strdup(n->msg); + /* If the progress differs this was probably intended to replace the notification + * but notify-send was used. So don't increment dup_count in this case + */ + if (orig->progress == n->progress) { + orig->dup_count++; + } else { + orig->progress = n->progress; + } + orig->start = time(NULL); + notification_free(n); + wake_up(); + return orig->id; } - orig->start = time(NULL); - notification_free(n); - wake_up(); - return orig->id; } } diff --git a/settings.c b/settings.c index 3fd1a4f..7b87d7a 100644 --- a/settings.c +++ b/settings.c @@ -175,6 +175,9 @@ void load_settings(char *cmdline_config_path) } } + settings.stack_duplicates = option_get_bool("global", "stack_duplicates", + "-stack_duplicates", true, "Merge multiple notifications with the same content"); + settings.startup_notification = option_get_bool("global", "startup_notification", "-startup_notification", false, diff --git a/settings.h b/settings.h index 64ef520..9481cce 100644 --- a/settings.h +++ b/settings.h @@ -4,6 +4,7 @@ typedef struct _settings { bool print_notifications; bool allow_markup; + bool stack_duplicates; char *font; char *normbgcolor; char *normfgcolor;