read color hints

this commit enables dunst to read color informations for the
notifications from the message.
This commit is contained in:
Sascha Kruse 2011-09-24 01:29:22 +02:00
parent 5a5211006e
commit 916a2c0c60
4 changed files with 57 additions and 6 deletions

9
README
View File

@ -71,6 +71,15 @@ OPTIONS
side of the screen. Y is measured from the top and down respectevly. see also EXAMPLES show the notification on monitor n.
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.
notify-send -h string:fgcolor:#ff4444
notify-send -h string:bgcolor:#4444ff
notify-send -h string:bgcolor:#4444ff -h string:fgcolor:#ff4444
FORMAT
fmt is a string containing placeholders. The placeholders will be replaced with the corresponding text, or if the text is not present, nothing. Possible placeholders are:

View File

@ -96,6 +96,14 @@ 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.
.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.
.TP
.BI "notify-send -h string:fgcolor:#ff4444"
.TP
.BI "notify-send -h string:bgcolor:#4444ff"
.TP
.BI "notify-send -h string:bgcolor:#4444ff -h string:fgcolor:#ff4444"
.SH FORMAT
fmt is a string containing placeholders. The placeholders will be replaced with the corresponding text, or if the text is not present, nothing.
Possible placeholders are:

26
dunst.c
View File

@ -30,6 +30,7 @@ typedef struct _msg_queue_t {
time_t start;
int timeout;
int urgency;
unsigned long colors[ColLast];
} msg_queue_t;
typedef struct _dimension_t {
@ -71,7 +72,7 @@ static int font_h;
static const char *format = "%s %b";
/* list functions */
msg_queue_t *append(msg_queue_t *queue, char *msg, int to, int urgency);
msg_queue_t *append(msg_queue_t *queue, char *msg, int to, int urgency, const char *fg, const char *bg);
msg_queue_t *delete(msg_queue_t *elem);
msg_queue_t *pop(msg_queue_t *queue);
int list_len(msg_queue_t *list);
@ -93,13 +94,28 @@ void usage(int exit_status);
#include "dunst_dbus.h"
msg_queue_t*
append(msg_queue_t *queue, char *msg, int to, int urgency) {
append(msg_queue_t *queue, char *msg, int to, int urgency, const char *fg, const char *bg) {
msg_queue_t *new = malloc(sizeof(msg_queue_t));
msg_queue_t *last;
Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
XColor color;
new->msg = fix_markup(msg);
new->urgency = urgency;
new->urgency = new->urgency > CRIT ? CRIT : new->urgency;
if(fg == NULL || !XAllocNamedColor(dc->dpy, cmap, fg, &color, &color)) {
new->colors[ColFG] = colors[new->urgency][ColFG];
} else {
new->colors[ColFG] = color.pixel;
}
if(bg == NULL || !XAllocNamedColor(dc->dpy, cmap, bg, &color, &color)) {
new->colors[ColBG] = colors[new->urgency][ColBG];
} else {
new->colors[ColBG] = color.pixel;
}
if(to == -1) {
new->timeout = timeouts[urgency];
} else {
@ -291,8 +307,8 @@ drawmsg(void) {
if(cur_msg->start == 0)
cur_msg->start = now;
drawrect(dc, 0, dc->y, width, font_h, True, BG(dc, colors[cur_msg->urgency]));
drawtext(dc, cur_msg->msg, colors[cur_msg->urgency]);
drawrect(dc, 0, dc->y, width, font_h, True, BG(dc, cur_msg->colors));
drawtext(dc, cur_msg->msg, cur_msg->colors);
dc->y += font_h;
cur_msg = cur_msg->next;
@ -612,7 +628,7 @@ main(int argc, char *argv[]) {
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);
msgqueue = append(msgqueue, strdup(argv[++i]), -1, 1, NULL, NULL);
listen_to_dbus = False;
}
else if(!strcmp(argv[i], "-mon")) {

View File

@ -165,6 +165,8 @@ notify(DBusMessage *dmsg) {
const char *summary;
const char *body;
const char *icon;
const char *fgcolor = NULL;
const char *bgcolor = NULL;
int urgency = 1;
char *msg;
dbus_uint32_t nid=0;
@ -203,6 +205,22 @@ notify(DBusMessage *dmsg) {
} while(dbus_message_iter_next(&hint));
}
if(!strcmp(hint_name, "fgcolor")) {
dbus_message_iter_next(&hint);
dbus_message_iter_recurse(&hint, &hint_value);
do {
dbus_message_iter_get_basic(&hint_value, &fgcolor);
} while(dbus_message_iter_next(&hint));
}
if(!strcmp(hint_name, "bgcolor")) {
dbus_message_iter_next(&hint);
dbus_message_iter_recurse(&hint, &hint_value);
do {
dbus_message_iter_get_basic(&hint_value, &bgcolor);
} while(dbus_message_iter_next(&hint));
}
} while(dbus_message_iter_next(&hint));
} while(dbus_message_iter_next(&hints));
@ -220,7 +238,7 @@ notify(DBusMessage *dmsg) {
if(expires > 0) {
expires = expires/1000;
}
msgqueue = append(msgqueue, msg, expires, urgency);
msgqueue = append(msgqueue, msg, expires, urgency, fgcolor, bgcolor);
drawmsg();
reply = dbus_message_new_method_return(dmsg);