From 17f94205b45f6fbdbe0bc23f12d1bde0af6118aa Mon Sep 17 00:00:00 2001 From: o9000 Date: Sat, 5 Dec 2015 11:42:07 +0100 Subject: [PATCH] Execplugin: add pango markup option --- src/battery/battery.c | 6 ++++-- src/clock/clock.c | 6 ++++-- src/config.c | 3 +++ src/execplugin/execplugin.c | 11 ++++++++--- src/execplugin/execplugin.h | 1 + src/taskbar/taskbar.c | 3 ++- src/taskbar/taskbarname.c | 3 ++- src/util/common.c | 8 ++++++-- src/util/common.h | 3 ++- 9 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/battery/battery.c b/src/battery/battery.c index 8ba1cb0..c6fca12 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -310,7 +310,8 @@ gboolean resize_battery(void *obj) buf_bat_percentage, strlen(buf_bat_percentage), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + FALSE); get_text_size2(bat2_font_desc, &bat_time_height_ink, &bat_time_height, @@ -320,7 +321,8 @@ gboolean resize_battery(void *obj) buf_bat_time, strlen(buf_bat_time), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + FALSE); if (panel_horizontal) { int new_size = (bat_percentage_width > bat_time_width) ? bat_percentage_width : bat_time_width; diff --git a/src/clock/clock.c b/src/clock/clock.c index c40e77c..dd3ad40 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -254,7 +254,8 @@ gboolean resize_clock(void *obj) buf_time, strlen(buf_time), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + FALSE); if (time2_format) { strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); get_text_size2(time2_font_desc, @@ -266,7 +267,8 @@ gboolean resize_clock(void *obj) buf_date, strlen(buf_date), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + FALSE); } if (panel_horizontal) { diff --git a/src/config.c b/src/config.c index 8da39ae..3acf852 100644 --- a/src/config.c +++ b/src/config.c @@ -531,6 +531,9 @@ void add_entry(char *key, char *value) } else if (strcmp(key, "execp_continuous") == 0) { Execp *execp = get_or_create_last_execp(); execp->backend->continuous = atoi(value); + } else if (strcmp(key, "execp_markup") == 0) { + Execp *execp = get_or_create_last_execp(); + execp->backend->has_markup = atoi(value); } else if (strcmp(key, "execp_cache_icon") == 0) { Execp *execp = get_or_create_last_execp(); execp->backend->cache_icon = atoi(value); diff --git a/src/execplugin/execplugin.c b/src/execplugin/execplugin.c index 114e6a3..52df9e1 100644 --- a/src/execplugin/execplugin.c +++ b/src/execplugin/execplugin.c @@ -246,7 +246,10 @@ void draw_execp(void *obj, cairo_t *c) pango_layout_set_alignment(layout, execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); - pango_layout_set_text(layout, execp->backend->text, strlen(execp->backend->text)); + if (!execp->backend->has_markup) + pango_layout_set_text(layout, execp->backend->text, strlen(execp->backend->text)); + else + pango_layout_set_markup(layout, execp->backend->text, strlen(execp->backend->text)); pango_cairo_update_layout(c, layout); draw_text(layout, @@ -295,7 +298,8 @@ gboolean resize_execp(void *obj) execp->backend->text, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + execp->backend->has_markup); } else { get_text_size2(execp->backend->font_desc, &txt_height_ink, @@ -309,7 +313,8 @@ gboolean resize_execp(void *obj) execp->backend->text, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + execp->backend->has_markup); } gboolean result = FALSE; diff --git a/src/execplugin/execplugin.h b/src/execplugin/execplugin.h index db4c62b..8f5566a 100644 --- a/src/execplugin/execplugin.h +++ b/src/execplugin/execplugin.h @@ -32,6 +32,7 @@ typedef struct ExecpBackend { PangoFontDescription *font_desc; Color font_color; int continuous; + gboolean has_markup; char *lclick_command; char *mclick_command; char *rclick_command; diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 8778df6..d80933e 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -255,7 +255,8 @@ void init_taskbar_panel(void *p) "TAjpg", 5, PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_END); + PANGO_ELLIPSIZE_END, + FALSE); if (!panel->g_task.maximum_width && panel_horizontal) panel->g_task.maximum_width = server.monitor[panel->monitor].width; diff --git a/src/taskbar/taskbarname.c b/src/taskbar/taskbarname.c index 83991b3..6d537ca 100644 --- a/src/taskbar/taskbarname.c +++ b/src/taskbar/taskbarname.c @@ -152,7 +152,8 @@ gboolean resize_taskbarname(void *obj) taskbar_name->name, strlen(taskbar_name->name), PANGO_WRAP_WORD_CHAR, - PANGO_ELLIPSIZE_NONE); + PANGO_ELLIPSIZE_NONE, + FALSE); if (panel_horizontal) { int new_size = name_width + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width)); diff --git a/src/util/common.c b/src/util/common.c index 7a7bef3..d7a5032 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -573,7 +573,8 @@ void get_text_size2(PangoFontDescription *font, char *text, int len, PangoWrapMode wrap, - PangoEllipsizeMode ellipsis) + PangoEllipsizeMode ellipsis, + gboolean markup) { PangoRectangle rect_ink, rect; @@ -588,7 +589,10 @@ void get_text_size2(PangoFontDescription *font, pango_layout_set_wrap(layout, wrap); pango_layout_set_ellipsize(layout, ellipsis); pango_layout_set_font_description(layout, font); - pango_layout_set_text(layout, text, len); + if (!markup) + pango_layout_set_text(layout, text, len); + else + pango_layout_set_markup(layout, text, len); pango_layout_get_pixel_extents(layout, &rect_ink, &rect); *height_ink = rect_ink.height; diff --git a/src/util/common.h b/src/util/common.h index 2b695b4..7e5407d 100644 --- a/src/util/common.h +++ b/src/util/common.h @@ -87,7 +87,8 @@ void get_text_size2(PangoFontDescription *font, char *text, int len, PangoWrapMode wrap, - PangoEllipsizeMode ellipsis); + PangoEllipsizeMode ellipsis, + gboolean markup); void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow);