diff options
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/sway/layout.c b/sway/layout.c index f600cf49..50a25442 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -186,40 +186,63 @@ 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 | sway_log(L_DEBUG,"setting width as %d",*old_width); |
208 | x += w; | 204 | } |
205 | scale += *old_width; | ||
206 | } | ||
207 | //Resize windows | ||
208 | if (scale > 0.1) { | ||
209 | scale = width / scale; | ||
210 | sway_log(L_DEBUG, "Arranging %p horizontally", container); | ||
211 | for (i = 0; i < container->children->length; ++i) { | ||
212 | swayc_t *child = container->children->items[i]; | ||
213 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale); | ||
214 | child->x = x + container->x; | ||
215 | child->y = y + container->y; | ||
216 | arrange_windows(child, child->width * scale, height); | ||
217 | x += child->width; | ||
218 | } | ||
209 | } | 219 | } |
210 | break; | 220 | break; |
211 | case L_VERT: | 221 | case L_VERT: |
212 | sway_log(L_DEBUG, "Arranging %p vertically", container); | 222 | //Calculate total height |
213 | for (i = 0; i < container->children->length; ++i) { | 223 | for (i = 0; i < container->children->length; ++i) { |
214 | swayc_t *child = container->children->items[i]; | 224 | int *old_height = &((swayc_t *)container->children->items[i])->height; |
215 | double percent = child->weight / total_weight; | 225 | if (container->children->length > 1) { |
216 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); | 226 | *old_height = height / (container->children->length - 1); |
217 | child->x = x + container->x; | 227 | } else { |
218 | child->y = y + container->y; | 228 | *old_height = height; |
219 | int w = width; | 229 | } |
220 | int h = height * percent; | 230 | if (*old_height == 0) { |
221 | arrange_windows(child, w, h); | 231 | } |
222 | y += h; | 232 | scale += *old_height; |
233 | } | ||
234 | //Resize | ||
235 | if (scale > 0.1) { | ||
236 | scale = height / scale; | ||
237 | sway_log(L_DEBUG, "Arranging %p vertically", container); | ||
238 | for (i = 0; i < container->children->length; ++i) { | ||
239 | swayc_t *child = container->children->items[i]; | ||
240 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale); | ||
241 | child->x = x + container->x; | ||
242 | child->y = y + container->y; | ||
243 | arrange_windows(child, width, child->height * scale); | ||
244 | y += child->height; | ||
245 | } | ||
223 | } | 246 | } |
224 | break; | 247 | break; |
225 | } | 248 | } |