From 0d8be7dccfac94ec6a2badffeb3125496fd35e49 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Fri, 22 Feb 2013 18:26:30 +0000 Subject: [PATCH] markup --- config.def.h | 1 + dunstrc | 11 +++++++++++ notification.c | 3 ++- settings.c | 3 +++ settings.h | 1 + x.c | 16 +++++++++++++++- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index 2cb999a..9cfc2b5 100644 --- a/config.def.h +++ b/config.def.h @@ -1,6 +1,7 @@ /* see example dunstrc for additional explanations about these options */ char *font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; +bool allow_markup = false; char *normbgcolor = "#1793D1"; char *normfgcolor = "#DDDDDD"; char *critbgcolor = "#ffaaaa"; diff --git a/dunstrc b/dunstrc index 5b5279f..fee2a79 100644 --- a/dunstrc +++ b/dunstrc @@ -1,6 +1,16 @@ [global] font = Monospace-10 + # allow a small subset of html markup: + # bold + # italic + # strikethrough + # underline + # + # 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: # %a appname # %s summary @@ -8,6 +18,7 @@ # %i iconname (including its path) # %I iconname (without its path) # %p progress value if set ([ 0%] to [100%]) or nothing + # Markup is allowed format = "%s\n%b" # Sort messages by urgency diff --git a/notification.c b/notification.c index ec4befa..ec16aa6 100644 --- a/notification.c +++ b/notification.c @@ -251,7 +251,8 @@ int notification_init(notification * n, int id) 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) n->msg = string_replace("\\n", "\n", n->msg); diff --git a/settings.c b/settings.c index b2f2b88..281b3b9 100644 --- a/settings.c +++ b/settings.c @@ -59,6 +59,9 @@ void load_settings(char *cmdline_config_path) settings.font = option_get_string("global", "font", "-fn", font, "The font dunst should use."); + settings.allow_markup = + option_get_bool("global", "allow_markup", "-markup", allow_markup, + "Allow markups."); settings.format = option_get_string("global", "format", "-format", format, "The format template for the notifictions"); diff --git a/settings.h b/settings.h index 4b7d449..ec3554d 100644 --- a/settings.h +++ b/settings.h @@ -3,6 +3,7 @@ typedef struct _settings { bool print_notifications; + bool allow_markup; char *font; char *normbgcolor; char *normfgcolor; diff --git a/x.c b/x.c index d4e1017..480ef8c 100644 --- a/x.c +++ b/x.c @@ -37,6 +37,8 @@ typedef struct _colored_layout { PangoLayout *l; color_t fg; color_t bg; + char *text; + PangoAttrList *attr; } colored_layout; cairo_ctx_t cairo_ctx; @@ -161,6 +163,7 @@ static void free_colored_layout(void *data) { colored_layout *cl = data; g_object_unref(cl->l); + g_free(cl->text); } 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); - 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)); n->displayed_height += 2 * settings.padding;