From 7a057b0b2e878973204d0e77fb8add8cce1ca313 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 15 Nov 2017 13:53:31 +0100 Subject: [PATCH 1/3] Close old notification when stacking Notification spec prohibits to reuse notification IDs (unless uint32 is exhausted). Therefore returning the same ID twice must not happen. Sending a signal, that the old notification timed out makes most sense. It wasn't closed by the user, nor by a CloseNotification call either. When we stack notifications, no interaction happened (the equivalent of timing out). --- src/queues.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/queues.c b/src/queues.c index 5185f1a..aaf364f 100644 --- a/src/queues.c +++ b/src/queues.c @@ -54,6 +54,7 @@ unsigned int queues_length_history() int queues_notification_insert(notification *n, int replaces_id) { + /* do not display the message, if the message is empty */ if (strlen(n->msg) == 0) { if (settings.always_run_script) { @@ -74,6 +75,8 @@ int queues_notification_insert(notification *n, int replaces_id) if (replaces_id == 0) { + n->id = ++next_notification_id; + if (settings.stack_duplicates) { int stacked = queues_stack_duplicate(n); if (stacked > 0) { @@ -82,8 +85,6 @@ int queues_notification_insert(notification *n, int replaces_id) } } - n->id = ++next_notification_id; - g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); } else { @@ -118,11 +119,17 @@ static int queues_stack_duplicate(notification *n) } else { orig->progress = n->progress; } - orig->start = g_get_monotonic_time(); - g_free(orig->msg); - orig->msg = g_strdup(n->msg); - notification_free(n); - return orig->id; + + iter->data = n; + + n->start = g_get_monotonic_time(); + + n->dup_count = orig->dup_count; + + notification_closed(orig, 1); + + notification_free(orig); + return n->id; } } @@ -138,10 +145,14 @@ static int queues_stack_duplicate(notification *n) } else { orig->progress = n->progress; } - g_free(orig->msg); - orig->msg = g_strdup(n->msg); - notification_free(n); - return orig->id; + iter->data = n; + + n->dup_count = orig->dup_count; + + notification_closed(orig, 1); + + notification_free(orig); + return n->id; } } From 1162f53f8cba180127a22df6746e768a85f6b2fb Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 15 Nov 2017 14:20:08 +0100 Subject: [PATCH 2/3] Change queues_stack_duplicate signature to bool --- src/queues.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/queues.c b/src/queues.c index aaf364f..76c3333 100644 --- a/src/queues.c +++ b/src/queues.c @@ -20,7 +20,7 @@ unsigned int displayed_limit = 0; int next_notification_id = 1; bool pause_displayed = false; -static int queues_stack_duplicate(notification *n); +static bool queues_stack_duplicate(notification *n); void queues_init(void) { @@ -74,19 +74,9 @@ int queues_notification_insert(notification *n, int replaces_id) } if (replaces_id == 0) { - n->id = ++next_notification_id; - - if (settings.stack_duplicates) { - int stacked = queues_stack_duplicate(n); - if (stacked > 0) { - // notification got stacked - return stacked; - } - } - - g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); - + if (!settings.stack_duplicates || !queues_stack_duplicate(n)) + g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); } else { n->id = replaces_id; if (!queues_notification_replace_id(n)) @@ -102,10 +92,10 @@ int queues_notification_insert(notification *n, int replaces_id) /* * Replaces duplicate notification and stacks it * - * Returns the notification id of the stacked notification - * Returns -1 if not notification could be stacked + * Returns %true, if notification got stacked + * Returns %false, if notification did not get stacked */ -static int queues_stack_duplicate(notification *n) +static bool queues_stack_duplicate(notification *n) { for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) { @@ -129,7 +119,7 @@ static int queues_stack_duplicate(notification *n) notification_closed(orig, 1); notification_free(orig); - return n->id; + return true; } } @@ -152,11 +142,11 @@ static int queues_stack_duplicate(notification *n) notification_closed(orig, 1); notification_free(orig); - return n->id; + return true; } } - return -1; + return false; } bool queues_notification_replace_id(notification *new) From 03c8301c26ff2cc0104cc51b0ed46863e9434f95 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 15 Nov 2017 14:22:52 +0100 Subject: [PATCH 3/3] Free old notifications when replaced Do not push old notifications to history, as there would be multiple notifications around with the same ID. --- src/queues.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/queues.c b/src/queues.c index 76c3333..81fb668 100644 --- a/src/queues.c +++ b/src/queues.c @@ -161,7 +161,7 @@ bool queues_notification_replace_id(notification *new) new->start = g_get_monotonic_time(); new->dup_count = old->dup_count; notification_run_script(new); - queues_history_push(old); + notification_free(old); return true; } } @@ -173,7 +173,7 @@ bool queues_notification_replace_id(notification *new) if (old->id == new->id) { iter->data = new; new->dup_count = old->dup_count; - queues_history_push(old); + notification_free(old); return true; } }