read color hints
this commit enables dunst to read color informations for the notifications from the message.
This commit is contained in:
parent
5a5211006e
commit
916a2c0c60
9
README
9
README
@ -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.
|
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
|
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:
|
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:
|
||||||
|
|
||||||
|
8
dunst.1
8
dunst.1
@ -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
|
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.
|
||||||
|
|
||||||
|
.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
|
.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.
|
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:
|
Possible placeholders are:
|
||||||
|
26
dunst.c
26
dunst.c
@ -30,6 +30,7 @@ typedef struct _msg_queue_t {
|
|||||||
time_t start;
|
time_t start;
|
||||||
int timeout;
|
int timeout;
|
||||||
int urgency;
|
int urgency;
|
||||||
|
unsigned long colors[ColLast];
|
||||||
} msg_queue_t;
|
} msg_queue_t;
|
||||||
|
|
||||||
typedef struct _dimension_t {
|
typedef struct _dimension_t {
|
||||||
@ -71,7 +72,7 @@ static int font_h;
|
|||||||
static const char *format = "%s %b";
|
static const char *format = "%s %b";
|
||||||
|
|
||||||
/* list functions */
|
/* 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 *delete(msg_queue_t *elem);
|
||||||
msg_queue_t *pop(msg_queue_t *queue);
|
msg_queue_t *pop(msg_queue_t *queue);
|
||||||
int list_len(msg_queue_t *list);
|
int list_len(msg_queue_t *list);
|
||||||
@ -93,13 +94,28 @@ void usage(int exit_status);
|
|||||||
#include "dunst_dbus.h"
|
#include "dunst_dbus.h"
|
||||||
|
|
||||||
msg_queue_t*
|
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 *new = malloc(sizeof(msg_queue_t));
|
||||||
msg_queue_t *last;
|
msg_queue_t *last;
|
||||||
|
Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
|
||||||
|
XColor color;
|
||||||
|
|
||||||
|
|
||||||
new->msg = fix_markup(msg);
|
new->msg = fix_markup(msg);
|
||||||
new->urgency = urgency;
|
new->urgency = urgency;
|
||||||
new->urgency = new->urgency > CRIT ? CRIT : new->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) {
|
if(to == -1) {
|
||||||
new->timeout = timeouts[urgency];
|
new->timeout = timeouts[urgency];
|
||||||
} else {
|
} else {
|
||||||
@ -291,8 +307,8 @@ drawmsg(void) {
|
|||||||
if(cur_msg->start == 0)
|
if(cur_msg->start == 0)
|
||||||
cur_msg->start = now;
|
cur_msg->start = now;
|
||||||
|
|
||||||
drawrect(dc, 0, dc->y, width, font_h, True, BG(dc, colors[cur_msg->urgency]));
|
drawrect(dc, 0, dc->y, width, font_h, True, BG(dc, cur_msg->colors));
|
||||||
drawtext(dc, cur_msg->msg, colors[cur_msg->urgency]);
|
drawtext(dc, cur_msg->msg, cur_msg->colors);
|
||||||
|
|
||||||
dc->y += font_h;
|
dc->y += font_h;
|
||||||
cur_msg = cur_msg->next;
|
cur_msg = cur_msg->next;
|
||||||
@ -612,7 +628,7 @@ main(int argc, char *argv[]) {
|
|||||||
else if(!strcmp(argv[i], "-cto"))
|
else if(!strcmp(argv[i], "-cto"))
|
||||||
timeouts[2] = atoi(argv[++i]);
|
timeouts[2] = atoi(argv[++i]);
|
||||||
else if(!strcmp(argv[i], "-msg")) {
|
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;
|
listen_to_dbus = False;
|
||||||
}
|
}
|
||||||
else if(!strcmp(argv[i], "-mon")) {
|
else if(!strcmp(argv[i], "-mon")) {
|
||||||
|
20
dunst_dbus.c
20
dunst_dbus.c
@ -165,6 +165,8 @@ notify(DBusMessage *dmsg) {
|
|||||||
const char *summary;
|
const char *summary;
|
||||||
const char *body;
|
const char *body;
|
||||||
const char *icon;
|
const char *icon;
|
||||||
|
const char *fgcolor = NULL;
|
||||||
|
const char *bgcolor = NULL;
|
||||||
int urgency = 1;
|
int urgency = 1;
|
||||||
char *msg;
|
char *msg;
|
||||||
dbus_uint32_t nid=0;
|
dbus_uint32_t nid=0;
|
||||||
@ -203,6 +205,22 @@ notify(DBusMessage *dmsg) {
|
|||||||
} while(dbus_message_iter_next(&hint));
|
} 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(&hint));
|
||||||
} while(dbus_message_iter_next(&hints));
|
} while(dbus_message_iter_next(&hints));
|
||||||
|
|
||||||
@ -220,7 +238,7 @@ notify(DBusMessage *dmsg) {
|
|||||||
if(expires > 0) {
|
if(expires > 0) {
|
||||||
expires = expires/1000;
|
expires = expires/1000;
|
||||||
}
|
}
|
||||||
msgqueue = append(msgqueue, msg, expires, urgency);
|
msgqueue = append(msgqueue, msg, expires, urgency, fgcolor, bgcolor);
|
||||||
drawmsg();
|
drawmsg();
|
||||||
|
|
||||||
reply = dbus_message_new_method_return(dmsg);
|
reply = dbus_message_new_method_return(dmsg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user