Move title_format from window to container.

This patch moves the title_format information from windows to containers.
Furthermore, it allows correctly setting it on window-less containers and
displays the title accordingly for split containers.

We now also dump and read title_format in GET_TREE / during restarts.

fixes #2120
This commit is contained in:
Ingo Bürk
2015-12-29 12:01:51 -05:00
parent cd172da6ae
commit 1f660a4cc4
15 changed files with 188 additions and 113 deletions

View File

@ -2000,3 +2000,47 @@ char *con_get_tree_representation(Con *con) {
return complete_buf;
}
/*
* Returns the container's title considering the current title format.
*
*/
i3String *con_parse_title_format(Con *con) {
assert(con->title_format != NULL);
i3Window *win = con->window;
/* We need to ensure that we only escape the window title if pango
* is used by the current font. */
const bool pango_markup = font_is_pango();
char *title;
char *class;
char *instance;
if (win == NULL) {
title = pango_escape_markup(con_get_tree_representation(con));
class = sstrdup("i3-frame");
instance = sstrdup("i3-frame");
} else {
title = pango_escape_markup(sstrdup((win->name == NULL) ? "" : i3string_as_utf8(win->name)));
class = pango_escape_markup(sstrdup((win->class_class == NULL) ? "" : win->class_class));
instance = pango_escape_markup(sstrdup((win->class_instance == NULL) ? "" : win->class_instance));
}
placeholder_t placeholders[] = {
{.name = "%title", .value = title},
{.name = "%class", .value = class},
{.name = "%instance", .value = instance}};
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
char *formatted_str = format_placeholders(con->title_format, &placeholders[0], num);
i3String *formatted = i3string_from_utf8(formatted_str);
i3string_set_markup(formatted, pango_markup);
FREE(formatted_str);
for (size_t i = 0; i < num; i++) {
FREE(placeholders[i].value);
}
return formatted;
}