filter duplicate messages
This commit is contained in:
parent
1b9d84f52a
commit
a5cc76c986
40
dunst.c
40
dunst.c
@ -322,7 +322,13 @@ void draw_win(void)
|
|||||||
n_buf[i].x_offset = 0;
|
n_buf[i].x_offset = 0;
|
||||||
if (iter) {
|
if (iter) {
|
||||||
n_buf[i].n = (notification *) iter->data;
|
n_buf[i].n = (notification *) iter->data;
|
||||||
|
if (n_buf[i].n->dup_count > 0) {
|
||||||
|
snprintf(n_buf[i].txt, BUFSIZ, "(%d) %s",
|
||||||
|
n_buf[i].n->dup_count,
|
||||||
|
n_buf[i].n->msg);
|
||||||
|
} else {
|
||||||
strncpy(n_buf[i].txt, n_buf[i].n->msg, BUFSIZ);
|
strncpy(n_buf[i].txt, n_buf[i].n->msg, BUFSIZ);
|
||||||
|
}
|
||||||
iter = iter->next;
|
iter = iter->next;
|
||||||
} else {
|
} else {
|
||||||
n_buf[i].n = NULL;
|
n_buf[i].n = NULL;
|
||||||
@ -614,6 +620,16 @@ void history_pop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_notification(notification *n) {
|
||||||
|
free(n->appname);
|
||||||
|
free(n->summary);
|
||||||
|
free(n->body);
|
||||||
|
free(n->icon);
|
||||||
|
free(n->msg);
|
||||||
|
free(n->dbus_client);
|
||||||
|
free(n);
|
||||||
|
}
|
||||||
|
|
||||||
int init_notification(notification * n, int id)
|
int init_notification(notification * n, int id)
|
||||||
{
|
{
|
||||||
const char *fg = NULL;
|
const char *fg = NULL;
|
||||||
@ -629,6 +645,30 @@ int init_notification(notification * n, int id)
|
|||||||
|
|
||||||
n->msg = fix_markup(n->msg);
|
n->msg = fix_markup(n->msg);
|
||||||
n->msg = strtrim(n->msg);
|
n->msg = strtrim(n->msg);
|
||||||
|
|
||||||
|
n->dup_count = 0;
|
||||||
|
|
||||||
|
/* check if n is a duplicate */
|
||||||
|
for (l_node * iter = notification_queue->head; iter; iter = iter->next) {
|
||||||
|
notification *orig = (notification *) iter->data;
|
||||||
|
if (strcmp(orig->msg, n->msg) == 0) {
|
||||||
|
orig->dup_count++;
|
||||||
|
free_notification(n);
|
||||||
|
return orig->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (l_node * iter = displayed_notifications->head; iter;
|
||||||
|
iter = iter->next) {
|
||||||
|
notification *orig = (notification *) iter->data;
|
||||||
|
if (strcmp(orig->msg, n->msg) == 0) {
|
||||||
|
orig->dup_count++;
|
||||||
|
orig->start = now;
|
||||||
|
free_notification(n);
|
||||||
|
return orig->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* urgency > CRIT -> array out of range */
|
/* urgency > CRIT -> array out of range */
|
||||||
n->urgency = n->urgency > CRIT ? CRIT : n->urgency;
|
n->urgency = n->urgency > CRIT ? CRIT : n->urgency;
|
||||||
|
|
||||||
|
1
dunst.h
1
dunst.h
@ -46,6 +46,7 @@ typedef struct _notification {
|
|||||||
int urgency;
|
int urgency;
|
||||||
int redisplayed; /* has been displayed before? */
|
int redisplayed; /* has been displayed before? */
|
||||||
int id;
|
int id;
|
||||||
|
int dup_count;
|
||||||
ColorSet *colors;
|
ColorSet *colors;
|
||||||
char *color_strings[2];
|
char *color_strings[2];
|
||||||
} notification;
|
} notification;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user