verbose-mode and output cleanup

This commit is contained in:
Sascha Kruse 2011-10-03 12:35:19 +02:00
parent 41401d0985
commit f4508c1dbe
3 changed files with 35 additions and 16 deletions

18
README
View File

@ -6,12 +6,11 @@ NAME
dunst - dmenu-ish universal notification system dunst - dmenu-ish universal notification system
SYNOPSIS SYNOPSIS
dunst [-geometry geom] [-fn font] [-nf color] [-nb color] [-lf color] [-lb color] [-cf color] [-cb color] [-to secs] [-nto secs] [-lto secs] [-cto secs] [-format fmt] [-key key] [-mod dunst [-geometry geom] [-fn font] [-nf color] [-nb color] [-lf color] [-lb color] [-cf color] [-cb color] [-to secs] [-nto secs] [-lto secs] [-cto secs] [-format fmt] [-key key] [-mod modifier] [-mon n] [-v]
modifier] [-mon n]
DESCRIPTION DESCRIPTION
dunst is a lightweight notification-daemon for the libnotify. Dnotify displays messages received via dbus or as commandline argument in a fashion similar to dmenu and additionally prints dunst is a lightweight notification-daemon for the libnotify. Dnotify displays messages received via dbus or as commandline argument in a fashion similar to dmenu and additionally prints them to stdout. Notifications
them to stdout. Notifications can be closed via mouseclick. can be closed via mouseclick.
OPTIONS OPTIONS
-h/--help -h/--help
@ -54,8 +53,7 @@ OPTIONS
close window by pressing key [a,b,space,Return etc.] (should be used in combination with -mod). close window by pressing key [a,b,space,Return etc.] (should be used in combination with -mod).
-mod modifier -mod modifier
defines the modifier for the key. Available modifiers are: ctrl,shift,mod1 (usually the alt-key),mod2,mod3,mod4 (usually windows key). This option can be used multiple times to defines the modifier for the key. Available modifiers are: ctrl,shift,mod1 (usually the alt-key),mod2,mod3,mod4 (usually windows key). This option can be used multiple times to combine modifiers.
combine modifiers.
-format fmt -format fmt
defines the format of the messages. See FORMAT. defines the format of the messages. See FORMAT.
@ -63,9 +61,11 @@ OPTIONS
-mon n show the notification on monitor n. -mon n show the notification on monitor n.
-geometry [[<width>]x<height>][+/-<X>+/-<y>] -geometry [[<width>]x<height>][+/-<X>+/-<y>]
The geometry of the message window. The height is measured in lines everything else in pixels. If the width is omitted but the height is given ("-geometry x2"), the message window The geometry of the message window. The height is measured in lines everything else in pixels. If the width is omitted but the height is given ("-geometry x2"), the message window expands over the whole screen
expands over the whole screen (dmenu-like). If width is 0, the window expands to the longest message displayed. A positive x is measured from the left, a negative from the right (dmenu-like). If width is 0, the window expands to the longest message displayed. A positive x is measured from the left, a negative from the right side of the screen. Y is measured from the top and down
side of the screen. Y is measured from the top and down respectevly. see also EXAMPLES show the notification on monitor n. respectevly. see also EXAMPLES show the notification on monitor n.
-v Activate verbose mode.
NOTIFY-SEND NOTIFY-SEND

View File

@ -35,6 +35,7 @@ dunst \- dmenu\-ish universal notification system
.IR modifier ] .IR modifier ]
.RB [ \-mon .RB [ \-mon
.IR n ] .IR n ]
.RB [ \-v ]
.P .P
.SH DESCRIPTION .SH DESCRIPTION
.B dunst .B dunst
@ -92,6 +93,9 @@ show the notification on monitor n.
.BI \-geometry " [[<width>]x<height>][+/-<X>+/-<y>]" .BI \-geometry " [[<width>]x<height>][+/-<X>+/-<y>]"
The geometry of the message window. The height is measured in lines everything else in pixels. If the width is omitted but the height is given ("-geometry x2"), the message window expands over the whole screen (dmenu-like). If width is 0, the window expands to the longest message displayed. A positive x is measured from the left, a negative from the right side of the screen. Y is measured from the top and down respectevly. see also EXAMPLES The geometry of the message window. The height is measured in lines everything else in pixels. If the width is omitted but the height is given ("-geometry x2"), the message window expands over the whole screen (dmenu-like). If width is 0, the window expands to the longest message displayed. A positive x is measured from the left, a negative from the right side of the screen. Y is measured from the top and down respectevly. see also EXAMPLES
show the notification on monitor n. show the notification on monitor n.
.TP
.BI \-v
Activate verbose mode.
.SH NOTIFY-SEND .SH NOTIFY-SEND
dunst is able to get different colors for a message via notify-send. For that, you have to add a hint via the -h option. dunst is able to get different colors for a message via notify-send. For that, you have to add a hint via the -h option.

25
dunst.c
View File

@ -69,6 +69,7 @@ static screen_info scr;
static dimension_t geometry; static dimension_t geometry;
static int font_h; static int font_h;
static const char *format = "%s %b"; static const char *format = "%s %b";
static int verbose = False;
/* list functions */ /* list functions */
msg_queue_t *append(msg_queue_t *queue, char *msg, int to, int urgency, const char *fg, const char *bg); msg_queue_t *append(msg_queue_t *queue, char *msg, int to, int urgency, const char *fg, const char *bg);
@ -81,6 +82,7 @@ int list_len(msg_queue_t *list);
void check_timeouts(void); void check_timeouts(void);
void delete_msg(msg_queue_t *elem); void delete_msg(msg_queue_t *elem);
void drawmsg(void); void drawmsg(void);
void dunst_printf(const char *fmt, ...);
char *fix_markup(char *str); char *fix_markup(char *str);
char *format_msg(const char *app, const char *sum, const char *body, const char *icon); char *format_msg(const char *app, const char *sum, const char *body, const char *icon);
void handleXEvents(void); void handleXEvents(void);
@ -122,7 +124,7 @@ append(msg_queue_t *queue, char *msg, int to, int urgency, const char *fg, const
} }
new->start = 0; new->start = 0;
printf("%s (timeout: %d, urgency: %d)\n", new->msg, new->timeout, urgency); dunst_printf("%s (timeout: %d, urgency: %d)\n", new->msg, new->timeout, urgency);
new->next = NULL; new->next = NULL;
if(queue == NULL) { if(queue == NULL) {
return new; return new;
@ -318,6 +320,18 @@ drawmsg(void) {
mapdc(dc, win, width, height*font_h); mapdc(dc, win, width, height*font_h);
} }
void
dunst_printf(const char *fmt, ...) {
va_list ap;
if(!verbose) {
return;
}
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
char char
*fix_markup(char *str) { *fix_markup(char *str) {
char *tmpString, *strpos, *tmppos; char *tmpString, *strpos, *tmppos;
@ -390,7 +404,6 @@ char
end = strstr(tmpString, ">"); end = strstr(tmpString, ">");
if(end != NULL) { if(end != NULL) {
replace_buf = strndup(start, end-start+1); replace_buf = strndup(start, end-start+1);
printf("replace_buf: '%s'\n", replace_buf);
tmpString = string_replace(replace_buf, "", tmpString); tmpString = string_replace(replace_buf, "", tmpString);
free(replace_buf); free(replace_buf);
} }
@ -400,7 +413,6 @@ char
end = strstr(tmpString, "/>"); end = strstr(tmpString, "/>");
if(end != NULL) { if(end != NULL) {
replace_buf = strndup(start, end-start+2); replace_buf = strndup(start, end-start+2);
printf("replace_buf: '%s'\n", replace_buf);
tmpString = string_replace(replace_buf, "", tmpString); tmpString = string_replace(replace_buf, "", tmpString);
free(replace_buf); free(replace_buf);
} }
@ -590,12 +602,15 @@ main(int argc, char *argv[]) {
if(!strcmp(argv[i], "-b")) { if(!strcmp(argv[i], "-b")) {
geometry.mask |= YNegative; geometry.mask |= YNegative;
} }
if(!strcmp(argv[i], "-v")) {
verbose = True;
}
else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
/* options */ /* options */
else if(i == argc-1) { else if(i == argc-1) {
printf("Option needs an argument\n"); fprintf(stderr, "Option needs an argument\n");
usage(1); usage(1);
} }
else if(!strcmp(argv[i], "-fn")) else if(!strcmp(argv[i], "-fn"))
@ -679,6 +694,6 @@ main(int argc, char *argv[]) {
void void
usage(int exit_status) { usage(int exit_status) {
fputs("usage: dunst [-h/--help] [-geometry geom] [-fn font] [-format fmt]\n[-nb color] [-nf color] [-lb color] [-lf color] [-cb color] [ -cf color]\n[-to secs] [-lto secs] [-cto secs] [-nto secs] [-key key] [-mod modifier] [-mon n]\n", stderr); fputs("usage: dunst [-h/--help] [-q] [-geometry geom] [-fn font] [-format fmt]\n[-nb color] [-nf color] [-lb color] [-lf color] [-cb color] [ -cf color]\n[-to secs] [-lto secs] [-cto secs] [-nto secs] [-key key] [-mod modifier] [-mon n]\n", stderr);
exit(exit_status); exit(exit_status);
} }