config for max history length

fix #177
This commit is contained in:
Sascha Kruse 2014-06-16 20:54:06 +02:00
parent 1221ac8c92
commit 3cd7f24fdd
7 changed files with 26 additions and 10 deletions

View File

@ -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] */ enum alignment align = left; /* text alignment [left/center/right] */
float bounce_freq = 1; /* determines the bounce frequency (if activated) */ float bounce_freq = 1; /* determines the bounce frequency (if activated) */
int sticky_history = True; int sticky_history = True;
int history_length = 20; /* max amount of notifications kept in history */
int show_indicators = True; int show_indicators = True;
int verbosity = 0; int verbosity = 0;
int word_wrap = False; int word_wrap = False;

23
dunst.c
View File

@ -149,16 +149,13 @@ void move_all_to_history()
notification_close(g_queue_peek_head_link(displayed)->data, 2); notification_close(g_queue_peek_head_link(displayed)->data, 2);
} }
notification *n = g_queue_pop_head(queue); while (queue->length > 0) {
while (n) { notification_close(g_queue_peek_head_link(queue)->data, 2);
g_queue_push_tail(history, n);
n = g_queue_pop_head(queue);
} }
} }
void history_pop(void) void history_pop(void)
{ {
if (g_queue_is_empty(history)) if (g_queue_is_empty(history))
return; return;
@ -171,6 +168,16 @@ void history_pop(void)
wake_up(); 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) void wake_up(void)
{ {
run(NULL); run(NULL);
@ -298,9 +305,9 @@ int main(int argc, char *argv[])
if (settings.startup_notification) { if (settings.startup_notification) {
notification *n = malloc(sizeof(notification)); notification *n = malloc(sizeof(notification));
n->appname = "dunst"; n->appname = strdup("dunst");
n->summary = "startup"; n->summary = strdup("startup");
n->body = "dunst is up and running"; n->body = strdup("dunst is up and running");
n->progress = 0; n->progress = 0;
n->timeout = 10; n->timeout = 10;
n->urgency = LOW; n->urgency = LOW;

View File

@ -6,6 +6,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "x.h" #include "x.h"
#include "notification.h"
#define ERR(msg) printf("%s : %d\n", (msg), __LINE__) #define ERR(msg) printf("%s : %d\n", (msg), __LINE__)
#define PERR(msg, errnum) printf("(%d) %s : %s\n", __LINE__, (msg), (strerror(errnum))) #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 check_timeouts(void);
void history_pop(void); void history_pop(void);
void history_push(notification *n);
void usage(int exit_status); void usage(int exit_status);
void move_all_to_history(void); void move_all_to_history(void);
void print_version(void); void print_version(void);

View File

@ -469,7 +469,7 @@ int notification_close_by_id(int id, int reason)
notification *n = iter->data; notification *n = iter->data;
if (n->id == id) { if (n->id == id) {
g_queue_remove(displayed, n); g_queue_remove(displayed, n);
g_queue_push_tail(history, n); history_push(n);
target = n; target = n;
break; break;
} }
@ -480,7 +480,7 @@ int notification_close_by_id(int id, int reason)
notification *n = iter->data; notification *n = iter->data;
if (n->id == id) { if (n->id == id) {
g_queue_remove(queue, n); g_queue_remove(queue, n);
g_queue_push_tail(history, n); history_push(n);
target = n; target = n;
break; break;
} }

View File

@ -42,6 +42,7 @@ typedef struct _notification {
} notification; } notification;
int notification_init(notification * n, int id); int notification_init(notification * n, int id);
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);

View File

@ -165,6 +165,10 @@ void load_settings(char *cmdline_config_path)
option_get_bool("global", "sticky_history", "-sticky_history", option_get_bool("global", "sticky_history", "-sticky_history",
sticky_history, sticky_history,
"Don't timeout notifications popped up from 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 = settings.show_indicators =
option_get_bool("global", "show_indicators", "-show_indicators", option_get_bool("global", "show_indicators", "-show_indicators",
show_indicators, show_indicators,

View File

@ -27,6 +27,7 @@ typedef struct _settings {
enum alignment align; enum alignment align;
float bounce_freq; float bounce_freq;
int sticky_history; int sticky_history;
int history_length;
int show_indicators; int show_indicators;
int verbosity; int verbosity;
int word_wrap; int word_wrap;