summaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c64
1 files changed, 57 insertions, 7 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 83bb20fb..37f4a066 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -86,6 +86,15 @@ static void apply_horiz_layout(struct sway_container *parent) {
86 if (!num_children) { 86 if (!num_children) {
87 return; 87 return;
88 } 88 }
89 size_t parent_offset = 0;
90 if (parent->parent->layout == L_TABBED) {
91 parent_offset = container_titlebar_height();
92 } else if (parent->parent->layout == L_STACKED) {
93 parent_offset =
94 container_titlebar_height() * parent->parent->children->length;
95 }
96 size_t parent_height = parent->height - parent_offset;
97
89 // Calculate total width of children 98 // Calculate total width of children
90 double total_width = 0; 99 double total_width = 0;
91 for (size_t i = 0; i < num_children; ++i) { 100 for (size_t i = 0; i < num_children; ++i) {
@@ -111,9 +120,9 @@ static void apply_horiz_layout(struct sway_container *parent) {
111 "Calculating arrangement for %p:%d (will scale %f by %f)", 120 "Calculating arrangement for %p:%d (will scale %f by %f)",
112 child, child->type, child->width, scale); 121 child, child->type, child->width, scale);
113 child->x = child_x; 122 child->x = child_x;
114 child->y = parent->y; 123 child->y = parent->y + parent_offset;
115 child->width = floor(child->width * scale); 124 child->width = floor(child->width * scale);
116 child->height = parent->height; 125 child->height = parent_height;
117 child_x += child->width; 126 child_x += child->width;
118 } 127 }
119 // Make last child use remaining width of parent 128 // Make last child use remaining width of parent
@@ -125,24 +134,33 @@ static void apply_vert_layout(struct sway_container *parent) {
125 if (!num_children) { 134 if (!num_children) {
126 return; 135 return;
127 } 136 }
137 size_t parent_offset = 0;
138 if (parent->parent->layout == L_TABBED) {
139 parent_offset = container_titlebar_height();
140 } else if (parent->parent->layout == L_STACKED) {
141 parent_offset =
142 container_titlebar_height() * parent->parent->children->length;
143 }
144 size_t parent_height = parent->height - parent_offset;
145
128 // Calculate total height of children 146 // Calculate total height of children
129 double total_height = 0; 147 double total_height = 0;
130 for (size_t i = 0; i < num_children; ++i) { 148 for (size_t i = 0; i < num_children; ++i) {
131 struct sway_container *child = parent->children->items[i]; 149 struct sway_container *child = parent->children->items[i];
132 if (child->height <= 0) { 150 if (child->height <= 0) {
133 if (num_children > 1) { 151 if (num_children > 1) {
134 child->height = parent->height / (num_children - 1); 152 child->height = parent_height / (num_children - 1);
135 } else { 153 } else {
136 child->height = parent->height; 154 child->height = parent_height;
137 } 155 }
138 } 156 }
139 total_height += child->height; 157 total_height += child->height;
140 } 158 }
141 double scale = parent->height / total_height; 159 double scale = parent_height / total_height;
142 160
143 // Resize 161 // Resize
144 wlr_log(L_DEBUG, "Arranging %p vertically", parent); 162 wlr_log(L_DEBUG, "Arranging %p vertically", parent);
145 double child_y = parent->y; 163 double child_y = parent->y + parent_offset;
146 struct sway_container *child; 164 struct sway_container *child;
147 for (size_t i = 0; i < num_children; ++i) { 165 for (size_t i = 0; i < num_children; ++i) {
148 child = parent->children->items[i]; 166 child = parent->children->items[i];
@@ -156,7 +174,33 @@ static void apply_vert_layout(struct sway_container *parent) {
156 child_y += child->height; 174 child_y += child->height;
157 } 175 }
158 // Make last child use remaining height of parent 176 // Make last child use remaining height of parent
159 child->height = parent->y + parent->height - child->y; 177 child->height = parent->y + parent_offset + parent_height - child->y;
178}
179
180static void apply_tabbed_layout(struct sway_container *parent) {
181 if (!parent->children->length) {
182 return;
183 }
184 for (int i = 0; i < parent->children->length; ++i) {
185 struct sway_container *child = parent->children->items[i];
186 child->x = parent->x;
187 child->y = parent->y;
188 child->width = parent->width;
189 child->height = parent->height;
190 }
191}
192
193static void apply_stacked_layout(struct sway_container *parent) {
194 if (!parent->children->length) {
195 return;
196 }
197 for (int i = 0; i < parent->children->length; ++i) {
198 struct sway_container *child = parent->children->items[i];
199 child->x = parent->x;
200 child->y = parent->y;
201 child->width = parent->width;
202 child->height = parent->height;
203 }
160} 204}
161 205
162void arrange_children_of(struct sway_container *parent) { 206void arrange_children_of(struct sway_container *parent) {
@@ -189,6 +233,12 @@ void arrange_children_of(struct sway_container *parent) {
189 case L_VERT: 233 case L_VERT:
190 apply_vert_layout(parent); 234 apply_vert_layout(parent);
191 break; 235 break;
236 case L_TABBED:
237 apply_tabbed_layout(parent);
238 break;
239 case L_STACKED:
240 apply_stacked_layout(parent);
241 break;
192 default: 242 default:
193 wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); 243 wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout);
194 apply_horiz_layout(parent); 244 apply_horiz_layout(parent);