more timeout option

added individual timeouts for each urgency-level
This commit is contained in:
Sascha Kruse 2011-09-16 22:24:16 +02:00
parent 8c48a33f31
commit c3440b97ac
3 changed files with 54 additions and 18 deletions

32
README
View File

@ -1,4 +1,4 @@
DNOTIFY(1) DNOTIFY(1)
DNOTIFY(1) DNOTIFY(1)
@ -6,11 +6,12 @@ NAME
dunst - dmenu-ish universal notification system
SYNOPSIS
dunst [-geometry geom] [-fn font] [-nf color] [-nb color] [-lf color] [-lb color] [-cf color] [-cb color] [-to secs] [-format fmt] [-key key] [-mod modifier] [-mon n]
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]
DESCRIPTION
dunst is a lightweight notification-daemon for the libnotify. It can also be used as a standalone notification system. Dnotify displays messages received via dbus or as commandline argument
in a fashion similar to dmenu and additionally prints them to stdout. Notifications can be closed via mouseclick.
dunst is a lightweight notification-daemon for the libnotify. It can also be used as a standalone notification system. Dnotify displays messages received via dbus or as commandline argu
ment in a fashion similar to dmenu and additionally prints them to stdout. Notifications can be closed via mouseclick.
OPTIONS
-h/--help
@ -41,14 +42,23 @@ OPTIONS
display msg instead of listening to notifications. This option can be used multiple times.
-to secs
display each message for secs seconds.
timeout for messages with low and normal urgency. Messages with a timeout of 0 will not dissappear automaticly (defaults to 10)
-nto secs
timeout for messages with normal urgency (defaults to 10)
-lto secs
timeout for messages with low urgency (defaults to 10)
-cto secs
timeout for messages with critical urgency (defaults to 0)
-key key
close window by pressing key [a,b,space,Return etc.] (should be used in combination with -mod).
-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 combine
modifiers.
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.
-format fmt
defines the format of the messages. See FORMAT.
@ -56,9 +66,9 @@ OPTIONS
-mon n show the notification on monitor n.
-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 show the notification on monitor n.
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.
FORMAT
@ -101,4 +111,4 @@ SEE also
DNOTIFY(1)
DNOTIFY(1)

17
dunst.1
View File

@ -21,6 +21,12 @@ dunst \- dmenu\-ish universal notification system
.IR color ]
.RB [ \-to
.IR secs ]
.RB [ \-nto
.IR secs ]
.RB [ \-lto
.IR secs ]
.RB [ \-cto
.IR secs ]
.RB [ \-format
.IR fmt ]
.RB [ \-key
@ -63,7 +69,16 @@ defines the forground color for critical messages.
display msg instead of listening to notifications. This option can be used multiple times.
.TP
.BI \-to " secs"
display each message for secs seconds.
timeout for messages with low and normal urgency. Messages with a timeout of 0 will not dissappear automaticly (defaults to 10)
.TP
.BI \-nto " secs"
timeout for messages with normal urgency (defaults to 10)
.TP
.BI \-lto " secs"
timeout for messages with low urgency (defaults to 10)
.TP
.BI \-cto " secs"
timeout for messages with critical urgency (defaults to 0)
.TP
.BI \-key " key"
close window by pressing key [a,b,space,Return etc.] (should be used in combination with -mod).

23
dunst.c
View File

@ -56,7 +56,7 @@ static unsigned long lowcol[ColLast];
static Atom utf8;
static DC *dc;
static Window win;
static double global_timeout = 10;
static double timeouts[] = { 10, 10, 0 };
static msg_queue_t *msgqueue = NULL;
static time_t now;
static int listen_to_dbus = True;
@ -96,11 +96,14 @@ append(msg_queue_t *queue, char *msg, int to, int urgency) {
msg_queue_t *last;
new->msg = xml_unescape(msg);
new->urgency = urgency;
if(to == -1) {
new->timeout = global_timeout;
new->urgency = new->urgency > 2 ? 2 : new->urgency;
new->timeout = timeouts[urgency];
} else {
new->timeout = to;
}
new->start = 0;
printf("%s (timeout: %d, urgency: %d)\n", new->msg, new->timeout, urgency);
new->next = NULL;
@ -201,7 +204,7 @@ delete_msg(msg_queue_t *elem) {
/* delete the oldest element */
tmp = msgqueue;
for(elem = msgqueue; elem->next != NULL; elem = elem->next) {
if(tmp->start > 0 && tmp->start < elem->start) {
if(tmp->start > 0 && tmp->start > elem->start) {
tmp = elem;
}
}
@ -572,8 +575,16 @@ main(int argc, char *argv[]) {
critbgcolor = argv[++i];
else if(!strcmp(argv[i], "-cf"))
critfgcolor = argv[++i];
else if(!strcmp(argv[i], "-to"))
global_timeout = atoi(argv[++i]);
else if(!strcmp(argv[i], "-to")) {
timeouts[0] = atoi(argv[++i]);
timeouts[1] = timeouts[0];
}
else if(!strcmp(argv[i], "-lto"))
timeouts[0] = atoi(argv[++i]);
else if(!strcmp(argv[i], "-nto"))
timeouts[1] = atoi(argv[++i]);
else if(!strcmp(argv[i], "-cto"))
timeouts[2] = atoi(argv[++i]);
else if(!strcmp(argv[i], "-msg")) {
msgqueue = append(msgqueue, strdup(argv[++i]), -1, 1);
listen_to_dbus = False;
@ -638,6 +649,6 @@ main(int argc, char *argv[]) {
void
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] [-key key] [-mod modifier] [-mon n] [-msg msg]\n", stderr);
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] [-msg msg]\n", stderr);
exit(exit_status);
}