diff options
author | Luminarys <kizunanohikari@gmail.com> | 2015-08-20 21:37:59 -0500 |
---|---|---|
committer | Luminarys <kizunanohikari@gmail.com> | 2015-08-20 21:37:59 -0500 |
commit | f589731f2912660bab6fdffc14ddcdbac3edd41c (patch) | |
tree | cda490ea65181959c777e623cb0f20f055f1d90a /sway/layout.c | |
parent | Style fixes (diff) | |
download | sway-f589731f2912660bab6fdffc14ddcdbac3edd41c.tar.gz sway-f589731f2912660bab6fdffc14ddcdbac3edd41c.tar.zst sway-f589731f2912660bab6fdffc14ddcdbac3edd41c.zip |
Rewrite of resize command to make it more sane
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/sway/layout.c b/sway/layout.c index c9c8fa7f..50e7b592 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -29,7 +29,7 @@ static int index_child(swayc_t *parent, swayc_t *child) { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | void add_child(swayc_t *parent, swayc_t *child) { | 31 | void add_child(swayc_t *parent, swayc_t *child) { |
32 | sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, | 32 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, |
33 | child->width, child->height, parent, parent->type, parent->width, parent->height); | 33 | child->width, child->height, parent, parent->type, parent->width, parent->height); |
34 | list_add(parent->children, child); | 34 | list_add(parent->children, child); |
35 | child->parent = parent; | 35 | child->parent = parent; |
@@ -40,7 +40,7 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | void add_floating(swayc_t *ws, swayc_t *child) { | 42 | void add_floating(swayc_t *ws, swayc_t *child) { |
43 | sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, | 43 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, |
44 | child->width, child->height, ws, ws->type, ws->width, ws->height); | 44 | child->width, child->height, ws, ws->type, ws->width, ws->height); |
45 | list_add(ws->floating, child); | 45 | list_add(ws->floating, child); |
46 | child->parent = ws; | 46 | child->parent = ws; |
@@ -144,7 +144,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
144 | child->y = y + container->gaps; | 144 | child->y = y + container->gaps; |
145 | child->width = width - container->gaps * 2; | 145 | child->width = width - container->gaps * 2; |
146 | child->height = height - container->gaps * 2; | 146 | child->height = height - container->gaps * 2; |
147 | sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y); | 147 | sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); |
148 | arrange_windows(child, -1, -1); | 148 | arrange_windows(child, -1, -1); |
149 | } | 149 | } |
150 | return; | 150 | return; |
@@ -193,7 +193,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
193 | default: | 193 | default: |
194 | // Calculate total width | 194 | // Calculate total width |
195 | for (i = 0; i < container->children->length; ++i) { | 195 | for (i = 0; i < container->children->length; ++i) { |
196 | int *old_width = &((swayc_t *)container->children->items[i])->width; | 196 | double *old_width = &((swayc_t *)container->children->items[i])->width; |
197 | if (*old_width <= 0) { | 197 | if (*old_width <= 0) { |
198 | if (container->children->length > 1) { | 198 | if (container->children->length > 1) { |
199 | *old_width = width / (container->children->length - 1); | 199 | *old_width = width / (container->children->length - 1); |
@@ -220,7 +220,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
220 | case L_VERT: | 220 | case L_VERT: |
221 | // Calculate total height | 221 | // Calculate total height |
222 | for (i = 0; i < container->children->length; ++i) { | 222 | for (i = 0; i < container->children->length; ++i) { |
223 | int *old_height = &((swayc_t *)container->children->items[i])->height; | 223 | double *old_height = &((swayc_t *)container->children->items[i])->height; |
224 | if (*old_height <= 0) { | 224 | if (*old_height <= 0) { |
225 | if (container->children->length > 1) { | 225 | if (container->children->length > 1) { |
226 | *old_height = height / (container->children->length - 1); | 226 | *old_height = height / (container->children->length - 1); |
@@ -371,34 +371,38 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) | |||
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | void recursive_resize(swayc_t *container, double amount, enum movement_direction dir) { | 374 | void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) { |
375 | int i; | 375 | int i; |
376 | bool layout_match = true; | 376 | bool layout_match = true; |
377 | if (dir == MOVE_LEFT) { | 377 | sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); |
378 | container->x += (int) amount; | 378 | if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) { |
379 | container->width += (int) amount; | 379 | container->width += amount; |
380 | layout_match = container->layout == L_HORIZ; | 380 | layout_match = container->layout == L_HORIZ; |
381 | } else if (dir == MOVE_RIGHT) { | 381 | } else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) { |
382 | container->width += (int) amount; | 382 | container->height += amount; |
383 | layout_match = container->layout == L_HORIZ; | ||
384 | } else if (dir == MOVE_UP) { | ||
385 | container->y += (int) amount; | ||
386 | container->height += (int) amount; | ||
387 | layout_match = container->layout == L_VERT; | ||
388 | } else if (dir == MOVE_DOWN) { | ||
389 | container->height += (int) amount; | ||
390 | layout_match = container->layout == L_VERT; | 383 | layout_match = container->layout == L_VERT; |
391 | } | 384 | } |
392 | if (container->type == C_VIEW) { | 385 | if (container->type == C_VIEW) { |
386 | struct wlc_geometry geometry = { | ||
387 | .origin = { | ||
388 | .x = container->x + container->gaps / 2, | ||
389 | .y = container->y + container->gaps / 2 | ||
390 | }, | ||
391 | .size = { | ||
392 | .w = container->width - container->gaps, | ||
393 | .h = container->height - container->gaps | ||
394 | } | ||
395 | }; | ||
396 | wlc_view_set_geometry(container->handle, edge, &geometry); | ||
393 | return; | 397 | return; |
394 | } | 398 | } |
395 | if (layout_match) { | 399 | if (layout_match) { |
396 | for (i = 0; i < container->children->length; i++) { | 400 | for (i = 0; i < container->children->length; i++) { |
397 | recursive_resize(container->children->items[i], amount/container->children->length, dir); | 401 | recursive_resize(container->children->items[i], amount/container->children->length, edge); |
398 | } | 402 | } |
399 | } else { | 403 | } else { |
400 | for (i = 0; i < container->children->length; i++) { | 404 | for (i = 0; i < container->children->length; i++) { |
401 | recursive_resize(container->children->items[i], amount, dir); | 405 | recursive_resize(container->children->items[i], amount, edge); |
402 | } | 406 | } |
403 | } | 407 | } |
404 | } | 408 | } |