This commit is contained in:
Sascha Kruse 2013-02-22 18:26:30 +00:00
parent bcc0c6621f
commit 0d8be7dccf
6 changed files with 33 additions and 2 deletions

View File

@ -1,6 +1,7 @@
/* see example dunstrc for additional explanations about these options */ /* see example dunstrc for additional explanations about these options */
char *font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; char *font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
bool allow_markup = false;
char *normbgcolor = "#1793D1"; char *normbgcolor = "#1793D1";
char *normfgcolor = "#DDDDDD"; char *normfgcolor = "#DDDDDD";
char *critbgcolor = "#ffaaaa"; char *critbgcolor = "#ffaaaa";

11
dunstrc
View File

@ -1,6 +1,16 @@
[global] [global]
font = Monospace-10 font = Monospace-10
# allow a small subset of html markup:
# <b>bold</b>
# <i>italic</i>
# <s>strikethrough<s/>
# <u>underline</u>
#
# for a complete reference see http://developer.gnome.org/pango/stable/PangoMarkupFormat.html
# If markup is not allowed, those tags will be stripped out of the message.
allow_markup = yes
# The format of the message. Possible variables are: # The format of the message. Possible variables are:
# %a appname # %a appname
# %s summary # %s summary
@ -8,6 +18,7 @@
# %i iconname (including its path) # %i iconname (including its path)
# %I iconname (without its path) # %I iconname (without its path)
# %p progress value if set ([ 0%] to [100%]) or nothing # %p progress value if set ([ 0%] to [100%]) or nothing
# Markup is allowed
format = "%s\n%b" format = "%s\n%b"
# Sort messages by urgency # Sort messages by urgency

View File

@ -251,7 +251,8 @@ int notification_init(notification * n, int id)
n->msg = string_replace("%p", "", n->msg); n->msg = string_replace("%p", "", n->msg);
} }
n->msg = notification_fix_markup(n->msg); if (!settings.allow_markup)
n->msg = notification_fix_markup(n->msg);
while (strstr(n->msg, "\\n") != NULL) while (strstr(n->msg, "\\n") != NULL)
n->msg = string_replace("\\n", "\n", n->msg); n->msg = string_replace("\\n", "\n", n->msg);

View File

@ -59,6 +59,9 @@ void load_settings(char *cmdline_config_path)
settings.font = settings.font =
option_get_string("global", "font", "-fn", font, option_get_string("global", "font", "-fn", font,
"The font dunst should use."); "The font dunst should use.");
settings.allow_markup =
option_get_bool("global", "allow_markup", "-markup", allow_markup,
"Allow markups.");
settings.format = settings.format =
option_get_string("global", "format", "-format", format, option_get_string("global", "format", "-format", format,
"The format template for the notifictions"); "The format template for the notifictions");

View File

@ -3,6 +3,7 @@
typedef struct _settings { typedef struct _settings {
bool print_notifications; bool print_notifications;
bool allow_markup;
char *font; char *font;
char *normbgcolor; char *normbgcolor;
char *normfgcolor; char *normfgcolor;

16
x.c
View File

@ -37,6 +37,8 @@ typedef struct _colored_layout {
PangoLayout *l; PangoLayout *l;
color_t fg; color_t fg;
color_t bg; color_t bg;
char *text;
PangoAttrList *attr;
} colored_layout; } colored_layout;
cairo_ctx_t cairo_ctx; cairo_ctx_t cairo_ctx;
@ -161,6 +163,7 @@ static void free_colored_layout(void *data)
{ {
colored_layout *cl = data; colored_layout *cl = data;
g_object_unref(cl->l); g_object_unref(cl->l);
g_free(cl->text);
} }
colored_layout *r_create_layout_from_notification(cairo_t *c, notification *n) colored_layout *r_create_layout_from_notification(cairo_t *c, notification *n)
@ -180,7 +183,18 @@ colored_layout *r_create_layout_from_notification(cairo_t *c, notification *n)
} }
r_setup_pango_layout(cl->l, width); r_setup_pango_layout(cl->l, width);
pango_layout_set_text(cl->l, n->text_to_render, -1); /* markup */
bool success = pango_parse_markup(n->text_to_render, -1, 0, &(cl->attr), &(cl->text), NULL, NULL);
if (success) {
pango_layout_set_text(cl->l, cl->text, -1);
pango_layout_set_attributes(cl->l, cl->attr);
} else {
cl->text = NULL;
cl->attr = NULL;
pango_layout_set_text(cl->l, n->text_to_render, -1);
printf("Error parsing markup\n");
}
pango_layout_get_pixel_size(cl->l, NULL, &(n->displayed_height)); pango_layout_get_pixel_size(cl->l, NULL, &(n->displayed_height));
n->displayed_height += 2 * settings.padding; n->displayed_height += 2 * settings.padding;