Skip to content

Commit

Permalink
markup
Browse files Browse the repository at this point in the history
  • Loading branch information
knopwob committed Feb 22, 2013
1 parent bcc0c66 commit 0d8be7d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.def.h
@@ -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";
Expand Down
11 changes: 11 additions & 0 deletions dunstrc
@@ -1,13 +1,24 @@
[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
# %b body # %b body
# %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
Expand Down
3 changes: 2 additions & 1 deletion notification.c
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions settings.c
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions settings.h
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion x.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 0d8be7d

Please sign in to comment.