diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 90 |
1 files changed, 38 insertions, 52 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 9cf18f61..f29a9adc 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "sway/tree/view.h" | 21 | #include "sway/tree/view.h" |
22 | #include "sway/tree/workspace.h" | 22 | #include "sway/tree/workspace.h" |
23 | #include "log.h" | 23 | #include "log.h" |
24 | #include "stringop.h" | ||
24 | 25 | ||
25 | static list_t *bfs_queue; | 26 | static list_t *bfs_queue; |
26 | 27 | ||
@@ -774,42 +775,36 @@ void container_calculate_title_height(struct sway_container *container) { | |||
774 | } | 775 | } |
775 | 776 | ||
776 | /** | 777 | /** |
777 | * Calculate and return the length of the concatenated child titles. | 778 | * Calculate and return the length of the tree representation. |
778 | * An example concatenated title is: V[Terminal, Firefox] | 779 | * An example tree representation is: V[Terminal, Firefox] |
779 | * If buffer is not NULL, also populate the buffer with the concatenated title. | 780 | * If buffer is not NULL, also populate the buffer with the representation. |
780 | */ | 781 | */ |
781 | static size_t concatenate_child_titles(struct sway_container *parent, | 782 | static size_t get_tree_representation(struct sway_container *parent, char *buffer) { |
782 | char *buffer) { | 783 | size_t len = 2; |
783 | size_t len = 2; // V[ | 784 | switch (parent->layout) { |
784 | if (buffer) { | 785 | case L_VERT: |
785 | switch (parent->layout) { | 786 | lenient_strcat(buffer, "V["); |
786 | case L_VERT: | 787 | break; |
787 | strcpy(buffer, "V["); | 788 | case L_HORIZ: |
788 | break; | 789 | lenient_strcat(buffer, "H["); |
789 | case L_HORIZ: | 790 | break; |
790 | strcpy(buffer, "H["); | 791 | case L_TABBED: |
791 | break; | 792 | lenient_strcat(buffer, "T["); |
792 | case L_TABBED: | 793 | break; |
793 | strcpy(buffer, "T["); | 794 | case L_STACKED: |
794 | break; | 795 | lenient_strcat(buffer, "S["); |
795 | case L_STACKED: | 796 | break; |
796 | strcpy(buffer, "S["); | 797 | case L_FLOATING: |
797 | break; | 798 | lenient_strcat(buffer, "F["); |
798 | case L_FLOATING: | 799 | break; |
799 | strcpy(buffer, "F["); | 800 | case L_NONE: |
800 | break; | 801 | lenient_strcat(buffer, "D["); |
801 | case L_NONE: | 802 | break; |
802 | strcpy(buffer, "D["); | ||
803 | break; | ||
804 | } | ||
805 | } | 803 | } |
806 | |||
807 | for (int i = 0; i < parent->children->length; ++i) { | 804 | for (int i = 0; i < parent->children->length; ++i) { |
808 | if (i != 0) { | 805 | if (i != 0) { |
809 | len += 1; | 806 | ++len; |
810 | if (buffer) { | 807 | lenient_strcat(buffer, " "); |
811 | strcat(buffer, " "); | ||
812 | } | ||
813 | } | 808 | } |
814 | struct sway_container *child = parent->children->items[i]; | 809 | struct sway_container *child = parent->children->items[i]; |
815 | const char *identifier = NULL; | 810 | const char *identifier = NULL; |
@@ -819,48 +814,39 @@ static size_t concatenate_child_titles(struct sway_container *parent, | |||
819 | identifier = view_get_app_id(child->sway_view); | 814 | identifier = view_get_app_id(child->sway_view); |
820 | } | 815 | } |
821 | } else { | 816 | } else { |
822 | identifier = child->name; | 817 | identifier = child->formatted_title; |
823 | } | 818 | } |
824 | if (identifier) { | 819 | if (identifier) { |
825 | len += strlen(identifier); | 820 | len += strlen(identifier); |
826 | if (buffer) { | 821 | lenient_strcat(buffer, identifier); |
827 | strcat(buffer, identifier); | ||
828 | } | ||
829 | } else { | 822 | } else { |
830 | len += 6; | 823 | len += 6; |
831 | if (buffer) { | 824 | lenient_strcat(buffer, "(null)"); |
832 | strcat(buffer, "(null)"); | ||
833 | } | ||
834 | } | 825 | } |
835 | } | 826 | } |
836 | 827 | ++len; | |
837 | len += 1; | 828 | lenient_strcat(buffer, "]"); |
838 | if (buffer) { | ||
839 | strcat(buffer, "]"); | ||
840 | } | ||
841 | return len; | 829 | return len; |
842 | } | 830 | } |
843 | 831 | ||
844 | void container_notify_child_title_changed(struct sway_container *container) { | 832 | void container_notify_subtree_changed(struct sway_container *container) { |
845 | if (!container || container->type != C_CONTAINER) { | 833 | if (!container || container->type != C_CONTAINER) { |
846 | return; | 834 | return; |
847 | } | 835 | } |
848 | if (container->formatted_title) { | 836 | free(container->formatted_title); |
849 | free(container->formatted_title); | 837 | container->formatted_title = NULL; |
850 | } | ||
851 | 838 | ||
852 | size_t len = concatenate_child_titles(container, NULL); | 839 | size_t len = get_tree_representation(container, NULL); |
853 | char *buffer = calloc(len + 1, sizeof(char)); | 840 | char *buffer = calloc(len + 1, sizeof(char)); |
854 | if (!sway_assert(buffer, "Unable to allocate title string")) { | 841 | if (!sway_assert(buffer, "Unable to allocate title string")) { |
855 | return; | 842 | return; |
856 | } | 843 | } |
857 | concatenate_child_titles(container, buffer); | 844 | get_tree_representation(container, buffer); |
858 | 845 | ||
859 | container->name = buffer; | ||
860 | container->formatted_title = buffer; | 846 | container->formatted_title = buffer; |
861 | container_calculate_title_height(container); | 847 | container_calculate_title_height(container); |
862 | container_update_title_textures(container); | 848 | container_update_title_textures(container); |
863 | container_notify_child_title_changed(container->parent); | 849 | container_notify_subtree_changed(container->parent); |
864 | } | 850 | } |
865 | 851 | ||
866 | size_t container_titlebar_height() { | 852 | size_t container_titlebar_height() { |