From 7a057b0b2e878973204d0e77fb8add8cce1ca313 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 15 Nov 2017 13:53:31 +0100 Subject: [PATCH] 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; } }