summaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c115
1 files changed, 60 insertions, 55 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 5d88325f..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
25static list_t *bfs_queue; 26static list_t *bfs_queue;
26 27
@@ -510,7 +511,7 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent,
510 struct sway_seat *seat = input_manager_current_seat(input_manager); 511 struct sway_seat *seat = input_manager_current_seat(input_manager);
511 512
512 // Tab titles 513 // Tab titles
513 int title_height = config->border_thickness * 2 + config->font_height; 514 int title_height = container_titlebar_height();
514 if (oy < parent->y + title_height) { 515 if (oy < parent->y + title_height) {
515 int tab_width = parent->width / parent->children->length; 516 int tab_width = parent->width / parent->children->length;
516 int child_index = (ox - parent->x) / tab_width; 517 int child_index = (ox - parent->x) / tab_width;
@@ -533,8 +534,23 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent,
533static struct sway_container *container_at_stacked( 534static struct sway_container *container_at_stacked(
534 struct sway_container *parent, double ox, double oy, 535 struct sway_container *parent, double ox, double oy,
535 struct wlr_surface **surface, double *sx, double *sy) { 536 struct wlr_surface **surface, double *sx, double *sy) {
536 // TODO 537 if (oy < parent->y || oy > parent->y + parent->height) {
537 return NULL; 538 return NULL;
539 }
540 struct sway_seat *seat = input_manager_current_seat(input_manager);
541
542 // Title bars
543 int title_height = container_titlebar_height();
544 int child_index = (oy - parent->y) / title_height;
545 if (child_index < parent->children->length) {
546 struct sway_container *child = parent->children->items[child_index];
547 return seat_get_focus_inactive(seat, child);
548 }
549
550 // Surfaces
551 struct sway_container *current = seat_get_active_child(seat, parent);
552
553 return container_at(current, ox, oy, surface, sx, sy);
538} 554}
539 555
540/** 556/**
@@ -759,42 +775,36 @@ void container_calculate_title_height(struct sway_container *container) {
759} 775}
760 776
761/** 777/**
762 * Calculate and return the length of the concatenated child titles. 778 * Calculate and return the length of the tree representation.
763 * An example concatenated title is: V[Terminal, Firefox] 779 * An example tree representation is: V[Terminal, Firefox]
764 * 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.
765 */ 781 */
766static size_t concatenate_child_titles(struct sway_container *parent, 782static size_t get_tree_representation(struct sway_container *parent, char *buffer) {
767 char *buffer) { 783 size_t len = 2;
768 size_t len = 2; // V[ 784 switch (parent->layout) {
769 if (buffer) { 785 case L_VERT:
770 switch (parent->layout) { 786 lenient_strcat(buffer, "V[");
771 case L_VERT: 787 break;
772 strcpy(buffer, "V["); 788 case L_HORIZ:
773 break; 789 lenient_strcat(buffer, "H[");
774 case L_HORIZ: 790 break;
775 strcpy(buffer, "H["); 791 case L_TABBED:
776 break; 792 lenient_strcat(buffer, "T[");
777 case L_TABBED: 793 break;
778 strcpy(buffer, "T["); 794 case L_STACKED:
779 break; 795 lenient_strcat(buffer, "S[");
780 case L_STACKED: 796 break;
781 strcpy(buffer, "S["); 797 case L_FLOATING:
782 break; 798 lenient_strcat(buffer, "F[");
783 case L_FLOATING: 799 break;
784 strcpy(buffer, "F["); 800 case L_NONE:
785 break; 801 lenient_strcat(buffer, "D[");
786 case L_NONE: 802 break;
787 strcpy(buffer, "D[");
788 break;
789 }
790 } 803 }
791
792 for (int i = 0; i < parent->children->length; ++i) { 804 for (int i = 0; i < parent->children->length; ++i) {
793 if (i != 0) { 805 if (i != 0) {
794 len += 1; 806 ++len;
795 if (buffer) { 807 lenient_strcat(buffer, " ");
796 strcat(buffer, " ");
797 }
798 } 808 }
799 struct sway_container *child = parent->children->items[i]; 809 struct sway_container *child = parent->children->items[i];
800 const char *identifier = NULL; 810 const char *identifier = NULL;
@@ -804,46 +814,41 @@ static size_t concatenate_child_titles(struct sway_container *parent,
804 identifier = view_get_app_id(child->sway_view); 814 identifier = view_get_app_id(child->sway_view);
805 } 815 }
806 } else { 816 } else {
807 identifier = child->name; 817 identifier = child->formatted_title;
808 } 818 }
809 if (identifier) { 819 if (identifier) {
810 len += strlen(identifier); 820 len += strlen(identifier);
811 if (buffer) { 821 lenient_strcat(buffer, identifier);
812 strcat(buffer, identifier);
813 }
814 } else { 822 } else {
815 len += 6; 823 len += 6;
816 if (buffer) { 824 lenient_strcat(buffer, "(null)");
817 strcat(buffer, "(null)");
818 }
819 } 825 }
820 } 826 }
821 827 ++len;
822 len += 1; 828 lenient_strcat(buffer, "]");
823 if (buffer) {
824 strcat(buffer, "]");
825 }
826 return len; 829 return len;
827} 830}
828 831
829void container_notify_child_title_changed(struct sway_container *container) { 832void container_notify_subtree_changed(struct sway_container *container) {
830 if (!container || container->type != C_CONTAINER) { 833 if (!container || container->type != C_CONTAINER) {
831 return; 834 return;
832 } 835 }
833 if (container->formatted_title) { 836 free(container->formatted_title);
834 free(container->formatted_title); 837 container->formatted_title = NULL;
835 }
836 838
837 size_t len = concatenate_child_titles(container, NULL); 839 size_t len = get_tree_representation(container, NULL);
838 char *buffer = calloc(len + 1, sizeof(char)); 840 char *buffer = calloc(len + 1, sizeof(char));
839 if (!sway_assert(buffer, "Unable to allocate title string")) { 841 if (!sway_assert(buffer, "Unable to allocate title string")) {
840 return; 842 return;
841 } 843 }
842 concatenate_child_titles(container, buffer); 844 get_tree_representation(container, buffer);
843 845
844 container->name = buffer;
845 container->formatted_title = buffer; 846 container->formatted_title = buffer;
846 container_calculate_title_height(container); 847 container_calculate_title_height(container);
847 container_update_title_textures(container); 848 container_update_title_textures(container);
848 container_notify_child_title_changed(container->parent); 849 container_notify_subtree_changed(container->parent);
850}
851
852size_t container_titlebar_height() {
853 return config->font_height + TITLEBAR_V_PADDING * 2;
849} 854}