Update to verbose mode

Remove dead code and print the notifications, when -print is given
This commit is contained in:
Sascha Kruse 2012-09-09 10:39:33 +02:00
parent c3767d1a7b
commit 1a4deea501
5 changed files with 29 additions and 51 deletions

View File

@ -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. 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> =item B<-v/--version>
print version information. print version information.

59
dunst.c
View File

@ -60,6 +60,7 @@ static screen_info scr;
static dimension_t geometry; static dimension_t geometry;
static XScreenSaverInfo *screensaver_info; static XScreenSaverInfo *screensaver_info;
static int font_h; static int font_h;
static int print_notifications = False;
int dunst_grab_errored = False; int dunst_grab_errored = False;
@ -100,6 +101,19 @@ void warn(const char *text, int urg);
void init_shortcut(keyboard_shortcut * shortcut); void init_shortcut(keyboard_shortcut * shortcut);
KeySym string_to_mask(char *str); 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) static int GrabXErrorHandler(Display * display, XErrorEvent * e)
{ {
dunst_grab_errored = True; 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) void apply_rules(notification * n)
{ {
if (l_is_empty(rules) || n == NULL) { 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->summary || !fnmatch(r->summary, n->summary, 0))
&& (!r->body || !fnmatch(r->body, n->body, 0)) && (!r->body || !fnmatch(r->body, n->body, 0))
&& (!r->icon || !fnmatch(r->icon, n->icon, 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->timeout = r->timeout != -1 ? r->timeout : n->timeout;
n->urgency = r->urgency != -1 ? r->urgency : n->urgency; n->urgency = r->urgency != -1 ? r->urgency : n->urgency;
n->color_strings[ColFG] = n->color_strings[ColFG] =
@ -898,6 +886,7 @@ int init_notification(notification * n, int id)
n->msg = fix_markup(n->msg); n->msg = fix_markup(n->msg);
n->dup_count = 0; n->dup_count = 0;
n->draw_txt_buf.txt = NULL; n->draw_txt_buf.txt = NULL;
@ -946,12 +935,6 @@ int init_notification(notification * n, int id)
n->redisplayed = False; 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) { if (id == 0) {
n->id = ++next_notification_id; n->id = ++next_notification_id;
} else { } else {
@ -965,6 +948,10 @@ int init_notification(notification * n, int id)
l_push(notification_queue, n); l_push(notification_queue, n);
} }
if (print_notifications)
print_notification(n);
return n->id; return n->id;
} }
@ -1342,6 +1329,7 @@ void parse_cmdline(int argc, char *argv[])
{"follow", required_argument, NULL, 'o'}, {"follow", required_argument, NULL, 'o'},
{"line_height", required_argument, NULL, 'H'}, {"line_height", required_argument, NULL, 'H'},
{"lh", required_argument, NULL, 'H'}, {"lh", required_argument, NULL, 'H'},
{"print", no_argument, NULL, 'V'},
{"version", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'v'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -1440,6 +1428,9 @@ void parse_cmdline(int argc, char *argv[])
case 'v': case 'v':
print_version(); print_version();
break; break;
case 'V':
print_notifications = True;
break;
default: default:
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
break; 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 = initrule();
rule->name = strdup(section); rule->name = strdup(section);
@ -1672,7 +1660,6 @@ void parse_dunstrc(char *cmdline_config_path)
fclose(config_file); fclose(config_file);
xdgWipeHandle(&xdg); xdgWipeHandle(&xdg);
print_rules();
} }
#endif /* STATIC_CONFIG */ #endif /* STATIC_CONFIG */

View File

@ -116,6 +116,8 @@
# Shell-like globbing will get expanded. # Shell-like globbing will get expanded.
# #
# NOTE: if you don't want a notification to be displayed, set the format to "" # 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] #[ignore]
## This notification will not be displayed ## This notification will not be displayed

12
utils.c
View File

@ -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 digit_count(int i)
{ {
int len = 0; int len = 0;

View File

@ -10,9 +10,6 @@ char *string_replace(const char *needle, const char *replacement,
/* exit with an error message */ /* exit with an error message */
void die(char * msg, int exit_value); void die(char * msg, int exit_value);
/* print depending on verbosity */
void dunst_printf(int level, const char *fmt, ...);
int digit_count(int i); int digit_count(int i);
#endif #endif