diff --git a/common/configopts.c b/common/configopts.c index 93a8a39b..d45d4d64 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -197,11 +197,11 @@ cfg_opt_t titlebar_opts[] = /** Text alignment. */ CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE), /** Titlebar markup string for normal windows. */ - CFG_STR((char *) "text_normal", (char *) "%t", CFGF_NONE), + CFG_STR((char *) "text_normal", (char *) "", CFGF_NONE), /** Titlebar markup string for focused windows. */ - CFG_STR((char *) "text_focus", (char *) "<bg color=\"#535d6c\"/>%t", CFGF_NONE), + CFG_STR((char *) "text_focus", (char *) "<bg color=\"#535d6c\"/><title/>", CFGF_NONE), /** Titlebar markup string for urgent windows. */ - CFG_STR((char *) "text_urgent", (char *) "<bg color=\"#ff4500\"/>%t", CFGF_NONE), + CFG_STR((char *) "text_urgent", (char *) "<bg color=\"#ff4500\"/><title/>", CFGF_NONE), CFG_AWESOME_END() }; /** This section defines general options. */ diff --git a/common/draw.c b/common/draw.c index 5036ed91..135fc415 100644 --- a/common/draw.c +++ b/common/draw.c @@ -228,19 +228,19 @@ static bool draw_text_markup_expand(draw_parser_data_t *data, const char *str, ssize_t slen) { - const char *elements[] = { "bg", NULL}; + const char *elements[] = { "bg", NULL }; markup_parser_data_t *p; int i; - p = markup_parser_data_new(elements, countof(elements)); + p = markup_parser_data_new(elements, NULL, countof(elements)); if(!markup_parse(p, str, slen)) return false; /* bg */ - if(p->attribute_values[0]) - for(i = 0; p->attribute_values[0][i]; i++) - if(!strcmp(p->attribute_values[0][i], "color")) + if(p->attribute_names[0]) + for(i = 0; p->attribute_names[0][i]; i++) + if(!a_strcmp(p->attribute_names[0][i], "color")) data->has_bg_color = draw_color_new(data->connection, data->phys_screen, p->attribute_values[0][i], &data->bg_color); diff --git a/common/markup.c b/common/markup.c index 06c6786b..495adce2 100644 --- a/common/markup.c +++ b/common/markup.c @@ -64,6 +64,12 @@ markup_parse_start_element(GMarkupParseContext *context __attribute__ ((unused)) p->attribute_names[i][j] = a_strdup(attribute_names[j]); p->attribute_values[i][j] = a_strdup(attribute_values[j]); } + if(p->elements_sub && p->elements_sub[i]) + { + asprintf(&newtext, "%s%s", NONULL(p->text), p->elements_sub[i]); + p_delete(&p->text); + p->text = newtext; + } return; } @@ -150,18 +156,21 @@ markup_parse_text(GMarkupParseContext *context __attribute__ ((unused)), /** Create a markup_parser_data_t structure with elements list. * \param elements an array of elements to look for, NULL terminated - * \param number of elements in the array (without NULL) + * \param elements_sub an optionnal array of values to substitude to elements, NULL + * terminated, or NULL if not needed + * \param nelem number of elements in the array (without NULL) * \return a pointer to an allocated markup_parser_data_t which must be freed - * with markup_parser_data_delete() + * with markup_parser_data_delete() */ markup_parser_data_t * -markup_parser_data_new(const char **elements, ssize_t nelem) +markup_parser_data_new(const char **elements, const char **elements_sub, ssize_t nelem) { markup_parser_data_t *p; p = p_new(markup_parser_data_t, 1); p->elements = elements; + p->elements_sub = elements_sub; p->attribute_names = p_new(char **, nelem); p->attribute_values = p_new(char **, nelem); diff --git a/common/markup.h b/common/markup.h index 17b9dc4f..f0306c74 100644 --- a/common/markup.h +++ b/common/markup.h @@ -28,11 +28,12 @@ typedef struct { char *text; const char **elements; + const char **elements_sub; char ***attribute_names; char ***attribute_values; } markup_parser_data_t; -markup_parser_data_t * markup_parser_data_new(const char **, ssize_t); +markup_parser_data_t * markup_parser_data_new(const char **, const char **, ssize_t); void markup_parser_data_delete(markup_parser_data_t **); bool markup_parse(markup_parser_data_t *data, const char *, ssize_t); diff --git a/titlebar.c b/titlebar.c index df6902e0..4b69ad9f 100644 --- a/titlebar.c +++ b/titlebar.c @@ -27,38 +27,23 @@ #include "titlebar.h" #include "screen.h" #include "layouts/floating.h" +#include "common/markup.h" extern AwesomeConf globalconf; static char * titlebar_markup_parse(client_t *c, const char *str, ssize_t len) { - const char *ps; - char *new; - int i = 0; - ssize_t clen; - - new = p_new(char, ++len); + const char *elements[] = { "title", NULL }; + const char *elements_sub[] = { c->name , NULL }; + markup_parser_data_t *p; - for(ps = str; *ps; ps++, i++) - if(*ps == '%') - { - ps++; - if(*ps == '%') - new[i] = '%'; - else if(*ps == 't') - { - clen = a_strlen(c->name); - len += clen; - p_realloc(&new, len); - a_strcat(new + i, len - i, c->name); - i += clen - 1; - } - } - else - new[i] = *ps; + p = markup_parser_data_new(elements, elements_sub, countof(elements)); - return new; + if(!markup_parse(p, str, len)) + return a_strdup(str); + + return p->text; } static char *