diff --git a/README.pod b/README.pod index 63ed897..ef97a75 100644 --- a/README.pod +++ b/README.pod @@ -88,6 +88,10 @@ see also EXAMPLES show the notification on monitor n. The height of a single line in pixel. If the height is smaller than the font height, it will get raised to the font height. +=item B<-print> + +Print notifications to stdout. This might be useful for logging, setting up rules or using the output in other scripts. + =item B<-v/--version> print version information. diff --git a/dunst.c b/dunst.c index 309cbe7..73aa062 100644 --- a/dunst.c +++ b/dunst.c @@ -60,6 +60,7 @@ static screen_info scr; static dimension_t geometry; static XScreenSaverInfo *screensaver_info; static int font_h; +static int print_notifications = False; int dunst_grab_errored = False; @@ -100,6 +101,19 @@ void warn(const char *text, int urg); void init_shortcut(keyboard_shortcut * shortcut); KeySym string_to_mask(char *str); +static void print_notification(notification *n) +{ + printf("{\n"); + printf("\tappname: %s\n", n->appname); + printf("\tsummary: %s\n", n->summary); + printf("\tbody: %s\n", n->body); + printf("\ticon: %s\n", n->icon); + printf("\turgency: %d\n", n->urgency); + printf("\tformatted: %s\n", n->msg); + printf("\tid: %d\n", n->id); + printf("}\n"); +} + static int GrabXErrorHandler(Display * display, XErrorEvent * e) { dunst_grab_errored = True; @@ -227,31 +241,6 @@ l_node *most_important(list * l) } } -void print_rule(rule_t * r) -{ - if (r == NULL) - return; - - dunst_printf(DEBUG, "%s %s %s %s %s %d %d %s %s %s\n", - r->name, - r->appname, - r->summary, - r->body, - r->icon, r->timeout, r->urgency, r->fg, r->bg, r->format); -} - -void print_rules(void) -{ - dunst_printf(DEBUG, "current rules:\n"); - if (l_is_empty(rules)) { - dunst_printf(DEBUG, "no rules present\n"); - return; - } - for (l_node * iter = rules->head; iter; iter = iter->next) { - print_rule((rule_t *) iter->data); - } -} - void apply_rules(notification * n) { if (l_is_empty(rules) || n == NULL) { @@ -265,7 +254,6 @@ void apply_rules(notification * n) && (!r->summary || !fnmatch(r->summary, n->summary, 0)) && (!r->body || !fnmatch(r->body, n->body, 0)) && (!r->icon || !fnmatch(r->icon, n->icon, 0))) { - dunst_printf(DEBUG, "matched rule: %s\n", r->name); n->timeout = r->timeout != -1 ? r->timeout : n->timeout; n->urgency = r->urgency != -1 ? r->urgency : n->urgency; n->color_strings[ColFG] = @@ -898,6 +886,7 @@ int init_notification(notification * n, int id) n->msg = fix_markup(n->msg); + n->dup_count = 0; n->draw_txt_buf.txt = NULL; @@ -946,12 +935,6 @@ int init_notification(notification * n, int id) n->redisplayed = False; - dunst_printf(MSG, "%s\n", n->msg); - dunst_printf(INFO, - "{\n appname: %s\n summary: %s\n body: %s\n icon: %s\n urgency: %d\n timeout: %d\n}", - n->appname, n->summary, n->body, n->icon, - n->urgency, n->timeout); - if (id == 0) { n->id = ++next_notification_id; } else { @@ -965,6 +948,10 @@ int init_notification(notification * n, int id) l_push(notification_queue, n); } + if (print_notifications) + print_notification(n); + + return n->id; } @@ -1342,6 +1329,7 @@ void parse_cmdline(int argc, char *argv[]) {"follow", required_argument, NULL, 'o'}, {"line_height", required_argument, NULL, 'H'}, {"lh", required_argument, NULL, 'H'}, + {"print", no_argument, NULL, 'V'}, {"version", no_argument, NULL, 'v'}, {0, 0, 0, 0} }; @@ -1440,6 +1428,9 @@ void parse_cmdline(int argc, char *argv[]) case 'v': print_version(); break; + case 'V': + print_notifications = True; + break; default: usage(EXIT_FAILURE); break; @@ -1481,9 +1472,6 @@ static rule_t *dunst_rules_find_or_create(const char *section) } } - /* rule not found in rules, create new one */ - dunst_printf(DEBUG, "adding rule %s\n", section); - rule = initrule(); rule->name = strdup(section); @@ -1672,7 +1660,6 @@ void parse_dunstrc(char *cmdline_config_path) fclose(config_file); xdgWipeHandle(&xdg); - print_rules(); } #endif /* STATIC_CONFIG */ diff --git a/dunstrc b/dunstrc index 4085614..db3bf4a 100644 --- a/dunstrc +++ b/dunstrc @@ -116,6 +116,8 @@ # Shell-like globbing will get expanded. # # NOTE: if you don't want a notification to be displayed, set the format to "" +# NOTE: It might be helpful to run dunst -print in a terminal in order to find +# fitting options for rules. #[ignore] ## This notification will not be displayed diff --git a/utils.c b/utils.c index 82575b4..ae5854f 100644 --- a/utils.c +++ b/utils.c @@ -44,18 +44,6 @@ char *string_replace(const char *needle, const char *replacement, } } -void dunst_printf(int level, const char *fmt, ...) -{ - va_list ap; - - if (level > verbosity) { - return; - } - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); -} - int digit_count(int i) { int len = 0; diff --git a/utils.h b/utils.h index e403b31..bde4408 100644 --- a/utils.h +++ b/utils.h @@ -10,9 +10,6 @@ char *string_replace(const char *needle, const char *replacement, /* exit with an error message */ void die(char * msg, int exit_value); -/* print depending on verbosity */ -void dunst_printf(int level, const char *fmt, ...); - int digit_count(int i); #endif