aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index b33985af..d19f13ae 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -348,7 +348,7 @@ struct sway_container *container_view_create(struct sway_container *sibling,
swayc, title, sibling, sibling ? sibling->type : 0, sibling->name);
// Setup values
swayc->sway_view = sway_view;
- swayc->name = title ? strdup(title) : NULL;
+ container_update_title(swayc, title);
swayc->width = 0;
swayc->height = 0;
@@ -611,3 +611,54 @@ void container_update_title_textures(struct sway_container *container) {
update_title_texture(container, &container->title_urgent,
&config->border_colors.urgent);
}
+
+void container_calculate_title_height(struct sway_container *container) {
+ if (!container->name) {
+ container->title_height = 0;
+ return;
+ }
+ cairo_t *cairo = cairo_create(NULL);
+ int height;
+ get_text_size(cairo, config->font, NULL, &height, 1, false,
+ "%s", container->name);
+ cairo_destroy(cairo);
+ container->title_height = height;
+}
+
+static void container_notify_child_title_changed(
+ struct sway_container *container) {
+ if (!container || container->type != C_CONTAINER) {
+ return;
+ }
+ if (container->layout != L_TABBED && container->layout != L_STACKED) {
+ return;
+ }
+ if (container->name) {
+ free(container->name);
+ }
+ // TODO: iterate children and concatenate their titles
+ container->name = strdup("");
+ container_calculate_title_height(container);
+ container_update_title_textures(container);
+ container_notify_child_title_changed(container->parent);
+}
+
+void container_update_title(struct sway_container *container,
+ const char *new_title) {
+ if (container->name && strcmp(container->name, new_title) == 0) {
+ return;
+ }
+ if (container->name) {
+ free(container->name);
+ }
+ container->name = strdup(new_title);
+ container_calculate_title_height(container);
+ container_update_title_textures(container);
+ container_notify_child_title_changed(container->parent);
+
+ size_t prev_max_height = config->font_height;
+ config_find_font_height(false);
+ if (config->font_height != prev_max_height) {
+ arrange_root();
+ }
+}