Merge pull request #391 from bebehei/flickerless-replace

Replace notifications flickerless
This commit is contained in:
Nikos Tsipinakis 2017-10-05 16:34:26 +03:00 committed by GitHub
commit 82d544e95e
2 changed files with 38 additions and 2 deletions

View File

@ -428,7 +428,6 @@ int notification_init(notification *n, int id)
if (id == 0) { if (id == 0) {
n->id = ++next_notification_id; n->id = ++next_notification_id;
} else { } else {
notification_close_by_id(id, -1);
n->id = id; n->id = id;
} }
@ -516,7 +515,8 @@ int notification_init(notification *n, int id)
} }
printf("skipping notification: %s %s\n", n->body, n->summary); printf("skipping notification: %s %s\n", n->body, n->summary);
} else { } else {
g_queue_insert_sorted(queue, n, notification_cmp_data, NULL); if (id == 0 || !notification_replace_by_id(n))
g_queue_insert_sorted(queue, n, notification_cmp_data, NULL);
} }
char *tmp = g_strconcat(n->summary, " ", n->body, NULL); char *tmp = g_strconcat(n->summary, " ", n->body, NULL);
@ -606,6 +606,41 @@ int notification_close(notification *n, int reason)
return notification_close_by_id(n->id, reason); return notification_close_by_id(n->id, reason);
} }
/*
* Replace the notification which matches the id field of
* the new notification. The given notification is inserted
* right in the same position as the old notification.
*
* Returns true, if a matching notification has been found
* and is replaced. Else false.
*/
bool notification_replace_by_id(notification *new)
{
for (GList *iter = g_queue_peek_head_link(displayed);
iter;
iter = iter->next) {
notification *old = iter->data;
if (old->id == new->id) {
iter->data = new;
history_push(old);
return true;
}
}
for (GList *iter = g_queue_peek_head_link(queue);
iter;
iter = iter->next) {
notification *old = iter->data;
if (old->id == new->id) {
iter->data = new;
history_push(old);
return true;
}
}
return false;
}
void notification_update_text_to_render(notification *n) void notification_update_text_to_render(notification *n)
{ {
if (n->text_to_render) { if (n->text_to_render) {

View File

@ -67,6 +67,7 @@ notification *notification_create(void);
int notification_init(notification *n, int id); int notification_init(notification *n, int id);
void notification_free(notification *n); void notification_free(notification *n);
int notification_close_by_id(int id, int reason); int notification_close_by_id(int id, int reason);
bool notification_replace_by_id(notification *n);
int notification_cmp(const void *a, const void *b); int notification_cmp(const void *a, const void *b);
int notification_cmp_data(const void *a, const void *b, void *data); int notification_cmp_data(const void *a, const void *b, void *data);
int notification_is_duplicate(const notification *a, const notification *b); int notification_is_duplicate(const notification *a, const notification *b);