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).
This commit is contained in:
Benedikt Heine 2017-11-15 13:53:31 +01:00
parent 62e50289f0
commit 7a057b0b2e

View File

@ -54,6 +54,7 @@ unsigned int queues_length_history()
int queues_notification_insert(notification *n, int replaces_id) int queues_notification_insert(notification *n, int replaces_id)
{ {
/* do not display the message, if the message is empty */ /* do not display the message, if the message is empty */
if (strlen(n->msg) == 0) { if (strlen(n->msg) == 0) {
if (settings.always_run_script) { if (settings.always_run_script) {
@ -74,6 +75,8 @@ int queues_notification_insert(notification *n, int replaces_id)
if (replaces_id == 0) { if (replaces_id == 0) {
n->id = ++next_notification_id;
if (settings.stack_duplicates) { if (settings.stack_duplicates) {
int stacked = queues_stack_duplicate(n); int stacked = queues_stack_duplicate(n);
if (stacked > 0) { 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); g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL);
} else { } else {
@ -118,11 +119,17 @@ static int queues_stack_duplicate(notification *n)
} else { } else {
orig->progress = n->progress; orig->progress = n->progress;
} }
orig->start = g_get_monotonic_time();
g_free(orig->msg); iter->data = n;
orig->msg = g_strdup(n->msg);
notification_free(n); n->start = g_get_monotonic_time();
return orig->id;
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 { } else {
orig->progress = n->progress; orig->progress = n->progress;
} }
g_free(orig->msg); iter->data = n;
orig->msg = g_strdup(n->msg);
notification_free(n); n->dup_count = orig->dup_count;
return orig->id;
notification_closed(orig, 1);
notification_free(orig);
return n->id;
} }
} }