From 3cd7f24fdd3ca41d30e37b5cbb8021bbc3fd2e97 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Mon, 16 Jun 2014 20:54:06 +0200 Subject: [PATCH] config for max history length fix #177 --- config.def.h | 1 + dunst.c | 23 +++++++++++++++-------- dunst.h | 2 ++ notification.c | 4 ++-- notification.h | 1 + settings.c | 4 ++++ settings.h | 1 + 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/config.def.h b/config.def.h index b40417b..65e36d8 100644 --- a/config.def.h +++ b/config.def.h @@ -25,6 +25,7 @@ int show_age_threshold = -1; /* show age of notification, when notification i enum alignment align = left; /* text alignment [left/center/right] */ float bounce_freq = 1; /* determines the bounce frequency (if activated) */ int sticky_history = True; +int history_length = 20; /* max amount of notifications kept in history */ int show_indicators = True; int verbosity = 0; int word_wrap = False; diff --git a/dunst.c b/dunst.c index bf2594f..c695002 100644 --- a/dunst.c +++ b/dunst.c @@ -149,16 +149,13 @@ void move_all_to_history() notification_close(g_queue_peek_head_link(displayed)->data, 2); } - notification *n = g_queue_pop_head(queue); - while (n) { - g_queue_push_tail(history, n); - n = g_queue_pop_head(queue); + while (queue->length > 0) { + notification_close(g_queue_peek_head_link(queue)->data, 2); } } void history_pop(void) { - if (g_queue_is_empty(history)) return; @@ -171,6 +168,16 @@ void history_pop(void) wake_up(); } +void history_push(notification *n) +{ + if (settings.history_length > 0 && history->length >= settings.history_length) { + notification *to_free = g_queue_pop_head(history); + notification_free(to_free); + } + + g_queue_push_tail(history, n); +} + void wake_up(void) { run(NULL); @@ -298,9 +305,9 @@ int main(int argc, char *argv[]) if (settings.startup_notification) { notification *n = malloc(sizeof(notification)); - n->appname = "dunst"; - n->summary = "startup"; - n->body = "dunst is up and running"; + n->appname = strdup("dunst"); + n->summary = strdup("startup"); + n->body = strdup("dunst is up and running"); n->progress = 0; n->timeout = 10; n->urgency = LOW; diff --git a/dunst.h b/dunst.h index ad17b19..c4c7519 100644 --- a/dunst.h +++ b/dunst.h @@ -6,6 +6,7 @@ #include #include "x.h" +#include "notification.h" #define ERR(msg) printf("%s : %d\n", (msg), __LINE__) #define PERR(msg, errnum) printf("(%d) %s : %s\n", __LINE__, (msg), (strerror(errnum))) @@ -34,6 +35,7 @@ void wake_up(void); void check_timeouts(void); void history_pop(void); +void history_push(notification *n); void usage(int exit_status); void move_all_to_history(void); void print_version(void); diff --git a/notification.c b/notification.c index 02f58db..a345386 100644 --- a/notification.c +++ b/notification.c @@ -469,7 +469,7 @@ int notification_close_by_id(int id, int reason) notification *n = iter->data; if (n->id == id) { g_queue_remove(displayed, n); - g_queue_push_tail(history, n); + history_push(n); target = n; break; } @@ -480,7 +480,7 @@ int notification_close_by_id(int id, int reason) notification *n = iter->data; if (n->id == id) { g_queue_remove(queue, n); - g_queue_push_tail(history, n); + history_push(n); target = n; break; } diff --git a/notification.h b/notification.h index 38a4e04..ba5d4a5 100644 --- a/notification.h +++ b/notification.h @@ -42,6 +42,7 @@ typedef struct _notification { } notification; int notification_init(notification * n, int id); +void notification_free(notification * n); int notification_close_by_id(int id, int reason); int notification_cmp(const void *a, const void *b); int notification_cmp_data(const void *a, const void *b, void *data); diff --git a/settings.c b/settings.c index 4eedc1d..7b22326 100644 --- a/settings.c +++ b/settings.c @@ -165,6 +165,10 @@ void load_settings(char *cmdline_config_path) option_get_bool("global", "sticky_history", "-sticky_history", sticky_history, "Don't timeout notifications popped up from history"); + settings.history_length = + option_get_int("global", "history_length", "-history_length", + history_length, + "Max amount of notifications kept in history"); settings.show_indicators = option_get_bool("global", "show_indicators", "-show_indicators", show_indicators, diff --git a/settings.h b/settings.h index 54fb406..26a049f 100644 --- a/settings.h +++ b/settings.h @@ -27,6 +27,7 @@ typedef struct _settings { enum alignment align; float bounce_freq; int sticky_history; + int history_length; int show_indicators; int verbosity; int word_wrap;