diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-21 07:12:05 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-21 07:12:05 -0400 |
commit | 464b49eda26f6a518bda39a8d07e1d9b0f498897 (patch) | |
tree | 7d0c55221b3028c2843da88b41029abac864b4a5 /sway/layout.c | |
parent | cc5713aee6525fd1783c1a9280079f7e9abcd882 (diff) | |
parent | 96ab21b2766096bdb42d79a0169d42b9ff00e2fb (diff) |
Merge pull request #101 from Luminarys/master
Added in basic resizing command.
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/sway/layout.c b/sway/layout.c index 8c011fdb..35aa4942 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -29,7 +29,7 @@ static int index_child(swayc_t *parent, swayc_t *child) { } void add_child(swayc_t *parent, swayc_t *child) { - sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, + sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, parent, parent->type, parent->width, parent->height); list_add(parent->children, child); child->parent = parent; @@ -40,7 +40,7 @@ void add_child(swayc_t *parent, swayc_t *child) { } void add_floating(swayc_t *ws, swayc_t *child) { - sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, + sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, ws, ws->type, ws->width, ws->height); list_add(ws->floating, child); child->parent = ws; @@ -109,7 +109,7 @@ swayc_t *remove_child(swayc_t *child) { } -void arrange_windows(swayc_t *container, int width, int height) { +void arrange_windows(swayc_t *container, double width, double height) { int i; if (width == -1 || height == -1) { sway_log(L_DEBUG, "Arranging layout for %p", container); @@ -144,7 +144,7 @@ void arrange_windows(swayc_t *container, int width, int height) { child->y = y + container->gaps; child->width = width - container->gaps * 2; child->height = height - container->gaps * 2; - sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y); + sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); arrange_windows(child, -1, -1); } return; @@ -190,7 +190,7 @@ void arrange_windows(swayc_t *container, int width, int height) { default: // Calculate total width for (i = 0; i < container->children->length; ++i) { - int *old_width = &((swayc_t *)container->children->items[i])->width; + double *old_width = &((swayc_t *)container->children->items[i])->width; if (*old_width <= 0) { if (container->children->length > 1) { *old_width = width / (container->children->length - 1); @@ -206,7 +206,7 @@ void arrange_windows(swayc_t *container, int width, int height) { sway_log(L_DEBUG, "Arranging %p horizontally", container); for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; - sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale); + sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); child->x = x + container->x; child->y = y + container->y; arrange_windows(child, child->width * scale, height); @@ -217,7 +217,7 @@ void arrange_windows(swayc_t *container, int width, int height) { case L_VERT: // Calculate total height for (i = 0; i < container->children->length; ++i) { - int *old_height = &((swayc_t *)container->children->items[i])->height; + double *old_height = &((swayc_t *)container->children->items[i])->height; if (*old_height <= 0) { if (container->children->length > 1) { *old_height = height / (container->children->length - 1); @@ -233,7 +233,7 @@ void arrange_windows(swayc_t *container, int width, int height) { sway_log(L_DEBUG, "Arranging %p vertically", container); for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; - sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale); + sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); child->x = x + container->x; child->y = y + container->y; arrange_windows(child, width, child->height * scale); @@ -364,3 +364,39 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) } } } + +void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) { + int i; + bool layout_match = true; + sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); + if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) { + container->width += amount; + layout_match = container->layout == L_HORIZ; + } else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) { + container->height += amount; + layout_match = container->layout == L_VERT; + } + if (container->type == C_VIEW) { + struct wlc_geometry geometry = { + .origin = { + .x = container->x + container->gaps / 2, + .y = container->y + container->gaps / 2 + }, + .size = { + .w = container->width - container->gaps, + .h = container->height - container->gaps + } + }; + wlc_view_set_geometry(container->handle, edge, &geometry); + return; + } + if (layout_match) { + for (i = 0; i < container->children->length; i++) { + recursive_resize(container->children->items[i], amount/container->children->length, edge); + } + } else { + for (i = 0; i < container->children->length; i++) { + recursive_resize(container->children->items[i], amount, edge); + } + } +} |