summaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c74
1 files changed, 48 insertions, 26 deletions
diff --git a/sway/layout.c b/sway/layout.c
index 37db2e52..54fdbcf8 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -186,40 +186,62 @@ void arrange_windows(swayc_t *container, int width, int height) {
186 break; 186 break;
187 } 187 }
188 188
189 double total_weight = 0; 189 x = y = 0;
190 for (i = 0; i < container->children->length; ++i) { 190 double scale = 0;
191 swayc_t *child = container->children->items[i];
192 total_weight += child->weight;
193 }
194
195 switch (container->layout) { 191 switch (container->layout) {
196 case L_HORIZ: 192 case L_HORIZ:
197 default: 193 default:
198 sway_log(L_DEBUG, "Arranging %p horizontally", container); 194 //Calculate total width
199 for (i = 0; i < container->children->length; ++i) { 195 for (i = 0; i < container->children->length; ++i) {
200 swayc_t *child = container->children->items[i]; 196 int *old_width = &((swayc_t *)container->children->items[i])->width;
201 double percent = child->weight / total_weight; 197 if (*old_width <= 0) {
202 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); 198 if (container->children->length > 1) {
203 child->x = x + container->x; 199 *old_width = width / (container->children->length - 1);
204 child->y = y + container->y; 200 } else {
205 int w = width * percent; 201 *old_width = width;
206 int h = height; 202 }
207 arrange_windows(child, w, h); 203 }
208 x += w; 204 scale += *old_width;
205 }
206 //Resize windows
207 if (scale > 0.1) {
208 scale = width / scale;
209 sway_log(L_DEBUG, "Arranging %p horizontally", container);
210 for (i = 0; i < container->children->length; ++i) {
211 swayc_t *child = container->children->items[i];
212 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale);
213 child->x = x + container->x;
214 child->y = y + container->y;
215 arrange_windows(child, child->width * scale, height);
216 x += child->width;
217 }
209 } 218 }
210 break; 219 break;
211 case L_VERT: 220 case L_VERT:
212 sway_log(L_DEBUG, "Arranging %p vertically", container); 221 //Calculate total height
213 for (i = 0; i < container->children->length; ++i) { 222 for (i = 0; i < container->children->length; ++i) {
214 swayc_t *child = container->children->items[i]; 223 int *old_height = &((swayc_t *)container->children->items[i])->height;
215 double percent = child->weight / total_weight; 224 if (*old_height <= 0) {
216 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); 225 if (container->children->length > 1) {
217 child->x = x + container->x; 226 *old_height = height / (container->children->length - 1);
218 child->y = y + container->y; 227 } else {
219 int w = width; 228 *old_height = height;
220 int h = height * percent; 229 }
221 arrange_windows(child, w, h); 230 }
222 y += h; 231 scale += *old_height;
232 }
233 //Resize
234 if (scale > 0.1) {
235 scale = height / scale;
236 sway_log(L_DEBUG, "Arranging %p vertically", container);
237 for (i = 0; i < container->children->length; ++i) {
238 swayc_t *child = container->children->items[i];
239 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale);
240 child->x = x + container->x;
241 child->y = y + container->y;
242 arrange_windows(child, width, child->height * scale);
243 y += child->height;
244 }
223 } 245 }
224 break; 246 break;
225 } 247 }