Merge pull request #439 from bebehei/duplicate-notifications

Duplicate notifications
This commit is contained in:
Benedikt Heine 2017-11-22 18:25:37 +01:00 committed by GitHub
commit 6e9a805017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,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)
{
@ -53,6 +53,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) {
@ -72,19 +73,9 @@ int queues_notification_insert(notification *n, int replaces_id)
}
if (replaces_id == 0) {
if (settings.stack_duplicates) {
int stacked = queues_stack_duplicate(n);
if (stacked > 0) {
// notification got stacked
return stacked;
}
}
n->id = ++next_notification_id;
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))
@ -100,10 +91,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) {
@ -117,11 +108,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 true;
}
}
@ -137,14 +134,18 @@ 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 true;
}
}
return -1;
return false;
}
bool queues_notification_replace_id(notification *new)
@ -159,7 +160,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;
}
}
@ -171,7 +172,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;
}
}