diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-03 15:02:16 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-03 15:12:00 +1000 |
commit | 55b307cddfa453fc003350a642a68735bc36e50e (patch) | |
tree | 4cc54f1be82db862fa4896b5da1d52868a273161 /sway/tree/container.c | |
parent | Render titles (diff) | |
download | sway-55b307cddfa453fc003350a642a68735bc36e50e.tar.gz sway-55b307cddfa453fc003350a642a68735bc36e50e.tar.zst sway-55b307cddfa453fc003350a642a68735bc36e50e.zip |
Calculate config->font_height based on existing container titles
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 53 |
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, | |||
348 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); | 348 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); |
349 | // Setup values | 349 | // Setup values |
350 | swayc->sway_view = sway_view; | 350 | swayc->sway_view = sway_view; |
351 | swayc->name = title ? strdup(title) : NULL; | 351 | container_update_title(swayc, title); |
352 | swayc->width = 0; | 352 | swayc->width = 0; |
353 | swayc->height = 0; | 353 | swayc->height = 0; |
354 | 354 | ||
@@ -611,3 +611,54 @@ void container_update_title_textures(struct sway_container *container) { | |||
611 | update_title_texture(container, &container->title_urgent, | 611 | update_title_texture(container, &container->title_urgent, |
612 | &config->border_colors.urgent); | 612 | &config->border_colors.urgent); |
613 | } | 613 | } |
614 | |||
615 | void container_calculate_title_height(struct sway_container *container) { | ||
616 | if (!container->name) { | ||
617 | container->title_height = 0; | ||
618 | return; | ||
619 | } | ||
620 | cairo_t *cairo = cairo_create(NULL); | ||
621 | int height; | ||
622 | get_text_size(cairo, config->font, NULL, &height, 1, false, | ||
623 | "%s", container->name); | ||
624 | cairo_destroy(cairo); | ||
625 | container->title_height = height; | ||
626 | } | ||
627 | |||
628 | static void container_notify_child_title_changed( | ||
629 | struct sway_container *container) { | ||
630 | if (!container || container->type != C_CONTAINER) { | ||
631 | return; | ||
632 | } | ||
633 | if (container->layout != L_TABBED && container->layout != L_STACKED) { | ||
634 | return; | ||
635 | } | ||
636 | if (container->name) { | ||
637 | free(container->name); | ||
638 | } | ||
639 | // TODO: iterate children and concatenate their titles | ||
640 | container->name = strdup(""); | ||
641 | container_calculate_title_height(container); | ||
642 | container_update_title_textures(container); | ||
643 | container_notify_child_title_changed(container->parent); | ||
644 | } | ||
645 | |||
646 | void container_update_title(struct sway_container *container, | ||
647 | const char *new_title) { | ||
648 | if (container->name && strcmp(container->name, new_title) == 0) { | ||
649 | return; | ||
650 | } | ||
651 | if (container->name) { | ||
652 | free(container->name); | ||
653 | } | ||
654 | container->name = strdup(new_title); | ||
655 | container_calculate_title_height(container); | ||
656 | container_update_title_textures(container); | ||
657 | container_notify_child_title_changed(container->parent); | ||
658 | |||
659 | size_t prev_max_height = config->font_height; | ||
660 | config_find_font_height(false); | ||
661 | if (config->font_height != prev_max_height) { | ||
662 | arrange_root(); | ||
663 | } | ||
664 | } | ||