Don't consider notifications duplicate if icon or urgency differ

Expand the duplication checking functionality to also check for urgency
and icons. If icons are turned off in the settings the icon check is
skipped.

Icons matching is done based on the given path, if the path differs or
an icon name is used for one notification but an absolute path for
another, the icons are considered different even if they refer to the
same file.
This commit is contained in:
Nikos Tsipinakis 2016-12-22 19:09:16 +02:00
parent f32659adb7
commit 6c9de72c7d
2 changed files with 12 additions and 6 deletions

View File

@ -143,6 +143,15 @@ int notification_cmp_data(const void *va, const void *vb, void *data)
return notification_cmp(va, vb); return notification_cmp(va, vb);
} }
int notification_is_duplicate(const notification *a, const notification *b)
{
return strcmp(a->appname, b->appname) == 0
&& strcmp(a->summary, b->summary) == 0
&& strcmp(a->body, b->body) == 0
&& (settings.icon_position != icons_off ? strcmp(a->icon, b->icon) == 0 : 1)
&& a->urgency == b->urgency;
}
/* /*
* Free the memory used by the given notification. * Free the memory used by the given notification.
*/ */
@ -373,9 +382,7 @@ int notification_init(notification * n, int id)
for (GList * iter = g_queue_peek_head_link(queue); iter; for (GList * iter = g_queue_peek_head_link(queue); iter;
iter = iter->next) { iter = iter->next) {
notification *orig = iter->data; notification *orig = iter->data;
if (strcmp(orig->appname, n->appname) == 0 if (notification_is_duplicate(orig, n)) {
&& strcmp(orig->summary, n->summary) == 0
&& strcmp(orig->body, n->body) == 0) {
/* If the progress differs this was probably intended to replace the notification /* If the progress differs this was probably intended to replace the notification
* but notify-send was used. So don't increment dup_count in this case * but notify-send was used. So don't increment dup_count in this case
*/ */
@ -398,9 +405,7 @@ int notification_init(notification * n, int id)
for (GList * iter = g_queue_peek_head_link(displayed); iter; for (GList * iter = g_queue_peek_head_link(displayed); iter;
iter = iter->next) { iter = iter->next) {
notification *orig = iter->data; notification *orig = iter->data;
if (strcmp(orig->appname, n->appname) == 0 if (notification_is_duplicate(orig, n)) {
&& strcmp(orig->summary, n->summary) == 0
&& strcmp(orig->body, n->body) == 0) {
/* notifications that differ only in progress hints should be expected equal, /* notifications that differ only in progress hints should be expected equal,
* but we want the latest message, with the latest hint value * but we want the latest message, with the latest hint value
*/ */

View File

@ -59,6 +59,7 @@ void notification_free(notification * n);
int notification_close_by_id(int id, int reason); int notification_close_by_id(int id, int reason);
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);
void notification_run_script(notification * n); void notification_run_script(notification * n);
int notification_close(notification * n, int reason); int notification_close(notification * n, int reason);
void notification_print(notification * n); void notification_print(notification * n);