diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 3b661046..00c40218 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -509,7 +509,8 @@ static void update_title_texture(struct sway_container *con, | |||
509 | 509 | ||
510 | double scale = output->wlr_output->scale; | 510 | double scale = output->wlr_output->scale; |
511 | int width = 0; | 511 | int width = 0; |
512 | int height = con->title_height * scale; | 512 | int height = config->font_height * scale; |
513 | int baseline; | ||
513 | 514 | ||
514 | // We must use a non-nil cairo_t for cairo_set_font_options to work. | 515 | // We must use a non-nil cairo_t for cairo_set_font_options to work. |
515 | // Therefore, we cannot use cairo_create(NULL). | 516 | // Therefore, we cannot use cairo_create(NULL). |
@@ -527,7 +528,7 @@ static void update_title_texture(struct sway_container *con, | |||
527 | to_cairo_subpixel_order(output->wlr_output->subpixel)); | 528 | to_cairo_subpixel_order(output->wlr_output->subpixel)); |
528 | } | 529 | } |
529 | cairo_set_font_options(c, fo); | 530 | cairo_set_font_options(c, fo); |
530 | get_text_size(c, config->font, &width, NULL, NULL, scale, | 531 | get_text_size(c, config->font, &width, NULL, &baseline, scale, |
531 | config->pango_markup, "%s", con->formatted_title); | 532 | config->pango_markup, "%s", con->formatted_title); |
532 | cairo_surface_destroy(dummy_surface); | 533 | cairo_surface_destroy(dummy_surface); |
533 | cairo_destroy(c); | 534 | cairo_destroy(c); |
@@ -536,6 +537,10 @@ static void update_title_texture(struct sway_container *con, | |||
536 | return; | 537 | return; |
537 | } | 538 | } |
538 | 539 | ||
540 | if (height > config->font_height * scale) { | ||
541 | height = config->font_height * scale; | ||
542 | } | ||
543 | |||
539 | cairo_surface_t *surface = cairo_image_surface_create( | 544 | cairo_surface_t *surface = cairo_image_surface_create( |
540 | CAIRO_FORMAT_ARGB32, width, height); | 545 | CAIRO_FORMAT_ARGB32, width, height); |
541 | cairo_t *cairo = cairo_create(surface); | 546 | cairo_t *cairo = cairo_create(surface); |
@@ -548,7 +553,7 @@ static void update_title_texture(struct sway_container *con, | |||
548 | PangoContext *pango = pango_cairo_create_context(cairo); | 553 | PangoContext *pango = pango_cairo_create_context(cairo); |
549 | cairo_set_source_rgba(cairo, class->text[0], class->text[1], | 554 | cairo_set_source_rgba(cairo, class->text[0], class->text[1], |
550 | class->text[2], class->text[3]); | 555 | class->text[2], class->text[3]); |
551 | cairo_move_to(cairo, 0, 0); | 556 | cairo_move_to(cairo, 0, config->font_baseline * scale - baseline); |
552 | 557 | ||
553 | pango_printf(cairo, config->font, scale, config->pango_markup, | 558 | pango_printf(cairo, config->font, scale, config->pango_markup, |
554 | "%s", con->formatted_title); | 559 | "%s", con->formatted_title); |
@@ -577,21 +582,6 @@ void container_update_title_textures(struct sway_container *container) { | |||
577 | container_damage_whole(container); | 582 | container_damage_whole(container); |
578 | } | 583 | } |
579 | 584 | ||
580 | void container_calculate_title_height(struct sway_container *container) { | ||
581 | if (!container->formatted_title) { | ||
582 | container->title_height = 0; | ||
583 | return; | ||
584 | } | ||
585 | cairo_t *cairo = cairo_create(NULL); | ||
586 | int height; | ||
587 | int baseline; | ||
588 | get_text_size(cairo, config->font, NULL, &height, &baseline, 1, | ||
589 | config->pango_markup, "%s", container->formatted_title); | ||
590 | cairo_destroy(cairo); | ||
591 | container->title_height = height; | ||
592 | container->title_baseline = baseline; | ||
593 | } | ||
594 | |||
595 | /** | 585 | /** |
596 | * Calculate and return the length of the tree representation. | 586 | * Calculate and return the length of the tree representation. |
597 | * An example tree representation is: V[Terminal, Firefox] | 587 | * An example tree representation is: V[Terminal, Firefox] |
@@ -657,7 +647,6 @@ void container_update_representation(struct sway_container *con) { | |||
657 | } | 647 | } |
658 | container_build_representation(con->pending.layout, con->pending.children, | 648 | container_build_representation(con->pending.layout, con->pending.children, |
659 | con->formatted_title); | 649 | con->formatted_title); |
660 | container_calculate_title_height(con); | ||
661 | container_update_title_textures(con); | 650 | container_update_title_textures(con); |
662 | } | 651 | } |
663 | if (con->pending.parent) { | 652 | if (con->pending.parent) { |
@@ -1628,10 +1617,11 @@ static void update_marks_texture(struct sway_container *con, | |||
1628 | 1617 | ||
1629 | double scale = output->wlr_output->scale; | 1618 | double scale = output->wlr_output->scale; |
1630 | int width = 0; | 1619 | int width = 0; |
1631 | int height = con->title_height * scale; | 1620 | int height = config->font_height * scale; |
1621 | int baseline; | ||
1632 | 1622 | ||
1633 | cairo_t *c = cairo_create(NULL); | 1623 | cairo_t *c = cairo_create(NULL); |
1634 | get_text_size(c, config->font, &width, NULL, NULL, scale, false, | 1624 | get_text_size(c, config->font, &width, NULL, &baseline, scale, false, |
1635 | "%s", buffer); | 1625 | "%s", buffer); |
1636 | cairo_destroy(c); | 1626 | cairo_destroy(c); |
1637 | 1627 | ||
@@ -1639,6 +1629,10 @@ static void update_marks_texture(struct sway_container *con, | |||
1639 | return; | 1629 | return; |
1640 | } | 1630 | } |
1641 | 1631 | ||
1632 | if (height > config->font_height) { | ||
1633 | height = config->font_height; | ||
1634 | } | ||
1635 | |||
1642 | cairo_surface_t *surface = cairo_image_surface_create( | 1636 | cairo_surface_t *surface = cairo_image_surface_create( |
1643 | CAIRO_FORMAT_ARGB32, width, height); | 1637 | CAIRO_FORMAT_ARGB32, width, height); |
1644 | cairo_t *cairo = cairo_create(surface); | 1638 | cairo_t *cairo = cairo_create(surface); |
@@ -1649,7 +1643,7 @@ static void update_marks_texture(struct sway_container *con, | |||
1649 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); | 1643 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); |
1650 | cairo_set_source_rgba(cairo, class->text[0], class->text[1], | 1644 | cairo_set_source_rgba(cairo, class->text[0], class->text[1], |
1651 | class->text[2], class->text[3]); | 1645 | class->text[2], class->text[3]); |
1652 | cairo_move_to(cairo, 0, 0); | 1646 | cairo_move_to(cairo, 0, config->font_baseline * scale - baseline); |
1653 | 1647 | ||
1654 | pango_printf(cairo, config->font, scale, false, "%s", buffer); | 1648 | pango_printf(cairo, config->font, scale, false, "%s", buffer); |
1655 | 1649 | ||