diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-05 12:36:50 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-05 22:29:37 +1000 |
commit | 228c478e8d11dd14972b237574146fd0d2d6b96c (patch) | |
tree | 819dfc4d6151ebb28d7db5b862d0ac4314d82fc3 /sway/tree/container.c | |
parent | Merge pull request #1918 from RyanDwyer/title-scissor (diff) | |
download | sway-228c478e8d11dd14972b237574146fd0d2d6b96c.tar.gz sway-228c478e8d11dd14972b237574146fd0d2d6b96c.tar.zst sway-228c478e8d11dd14972b237574146fd0d2d6b96c.zip |
Implement title_format
This implements the title_format command, with a new placeholder %shell
which gets substituted with the view type (xwayland, xdg_shell_v6 or
wl_shell).
Example config:
for_window [title=".*"] title_format %title (class=%class instance=%instance shell=%shell)
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 9fb47020..e1be32d1 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -348,7 +348,6 @@ 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 | container_update_title(swayc, title); | ||
352 | swayc->width = 0; | 351 | swayc->width = 0; |
353 | swayc->height = 0; | 352 | swayc->height = 0; |
354 | 353 | ||
@@ -572,7 +571,7 @@ static void update_title_texture(struct sway_container *con, | |||
572 | if (*texture) { | 571 | if (*texture) { |
573 | wlr_texture_destroy(*texture); | 572 | wlr_texture_destroy(*texture); |
574 | } | 573 | } |
575 | if (!con->name) { | 574 | if (!con->formatted_title) { |
576 | return; | 575 | return; |
577 | } | 576 | } |
578 | 577 | ||
@@ -581,7 +580,8 @@ static void update_title_texture(struct sway_container *con, | |||
581 | int height = config->font_height * scale; | 580 | int height = config->font_height * scale; |
582 | 581 | ||
583 | cairo_t *c = cairo_create(NULL); | 582 | cairo_t *c = cairo_create(NULL); |
584 | get_text_size(c, config->font, &width, NULL, scale, false, "%s", con->name); | 583 | get_text_size(c, config->font, &width, NULL, scale, false, |
584 | "%s", con->formatted_title); | ||
585 | cairo_destroy(c); | 585 | cairo_destroy(c); |
586 | 586 | ||
587 | cairo_surface_t *surface = cairo_image_surface_create( | 587 | cairo_surface_t *surface = cairo_image_surface_create( |
@@ -596,7 +596,7 @@ static void update_title_texture(struct sway_container *con, | |||
596 | class->text[2], class->text[3]); | 596 | class->text[2], class->text[3]); |
597 | cairo_move_to(cairo, 0, 0); | 597 | cairo_move_to(cairo, 0, 0); |
598 | 598 | ||
599 | pango_printf(cairo, config->font, scale, false, "%s", con->name); | 599 | pango_printf(cairo, config->font, scale, false, "%s", con->formatted_title); |
600 | 600 | ||
601 | cairo_surface_flush(surface); | 601 | cairo_surface_flush(surface); |
602 | unsigned char *data = cairo_image_surface_get_data(surface); | 602 | unsigned char *data = cairo_image_surface_get_data(surface); |
@@ -622,57 +622,31 @@ void container_update_title_textures(struct sway_container *container) { | |||
622 | } | 622 | } |
623 | 623 | ||
624 | void container_calculate_title_height(struct sway_container *container) { | 624 | void container_calculate_title_height(struct sway_container *container) { |
625 | if (!container->name) { | 625 | if (!container->formatted_title) { |
626 | container->title_height = 0; | 626 | container->title_height = 0; |
627 | return; | 627 | return; |
628 | } | 628 | } |
629 | cairo_t *cairo = cairo_create(NULL); | 629 | cairo_t *cairo = cairo_create(NULL); |
630 | int height; | 630 | int height; |
631 | get_text_size(cairo, config->font, NULL, &height, 1, false, | 631 | get_text_size(cairo, config->font, NULL, &height, 1, false, |
632 | "%s", container->name); | 632 | "%s", container->formatted_title); |
633 | cairo_destroy(cairo); | 633 | cairo_destroy(cairo); |
634 | container->title_height = height; | 634 | container->title_height = height; |
635 | } | 635 | } |
636 | 636 | ||
637 | static void container_notify_child_title_changed( | 637 | void container_notify_child_title_changed(struct sway_container *container) { |
638 | struct sway_container *container) { | ||
639 | if (!container || container->type != C_CONTAINER) { | 638 | if (!container || container->type != C_CONTAINER) { |
640 | return; | 639 | return; |
641 | } | 640 | } |
642 | if (container->layout != L_TABBED && container->layout != L_STACKED) { | 641 | if (container->layout != L_TABBED && container->layout != L_STACKED) { |
643 | return; | 642 | return; |
644 | } | 643 | } |
645 | if (container->name) { | 644 | if (container->formatted_title) { |
646 | free(container->name); | 645 | free(container->formatted_title); |
647 | } | 646 | } |
648 | // TODO: iterate children and concatenate their titles | 647 | // TODO: iterate children and concatenate their titles |
649 | container->name = strdup(""); | 648 | container->formatted_title = strdup(""); |
650 | container_calculate_title_height(container); | 649 | container_calculate_title_height(container); |
651 | container_update_title_textures(container); | 650 | container_update_title_textures(container); |
652 | container_notify_child_title_changed(container->parent); | 651 | container_notify_child_title_changed(container->parent); |
653 | } | 652 | } |
654 | |||
655 | void container_update_title(struct sway_container *container, | ||
656 | const char *new_title) { | ||
657 | if (!new_title) { | ||
658 | new_title = ""; | ||
659 | } | ||
660 | |||
661 | if (container->name && strcmp(container->name, new_title) == 0) { | ||
662 | return; | ||
663 | } | ||
664 | |||
665 | if (container->name) { | ||
666 | free(container->name); | ||
667 | } | ||
668 | container->name = strdup(new_title); | ||
669 | container_calculate_title_height(container); | ||
670 | container_update_title_textures(container); | ||
671 | container_notify_child_title_changed(container->parent); | ||
672 | |||
673 | size_t prev_max_height = config->font_height; | ||
674 | config_find_font_height(false); | ||
675 | if (config->font_height != prev_max_height) { | ||
676 | arrange_root(); | ||
677 | } | ||
678 | } | ||