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 | Merge pull request #106 from FSMaxB/session-files (diff) | |
parent | Fixes to resizing and added in resize lock once boundaries are exceeded (diff) | |
download | sway-464b49eda26f6a518bda39a8d07e1d9b0f498897.tar.gz sway-464b49eda26f6a518bda39a8d07e1d9b0f498897.tar.zst sway-464b49eda26f6a518bda39a8d07e1d9b0f498897.zip |
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) { | |||
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; |
@@ -109,7 +109,7 @@ swayc_t *remove_child(swayc_t *child) { | |||
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | void arrange_windows(swayc_t *container, int width, int height) { | 112 | void arrange_windows(swayc_t *container, double width, double height) { |
113 | int i; | 113 | int i; |
114 | if (width == -1 || height == -1) { | 114 | if (width == -1 || height == -1) { |
115 | sway_log(L_DEBUG, "Arranging layout for %p", container); | 115 | sway_log(L_DEBUG, "Arranging layout for %p", container); |
@@ -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; |
@@ -190,7 +190,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
190 | default: | 190 | default: |
191 | // Calculate total width | 191 | // Calculate total width |
192 | for (i = 0; i < container->children->length; ++i) { | 192 | for (i = 0; i < container->children->length; ++i) { |
193 | int *old_width = &((swayc_t *)container->children->items[i])->width; | 193 | double *old_width = &((swayc_t *)container->children->items[i])->width; |
194 | if (*old_width <= 0) { | 194 | if (*old_width <= 0) { |
195 | if (container->children->length > 1) { | 195 | if (container->children->length > 1) { |
196 | *old_width = width / (container->children->length - 1); | 196 | *old_width = width / (container->children->length - 1); |
@@ -206,7 +206,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
206 | sway_log(L_DEBUG, "Arranging %p horizontally", container); | 206 | sway_log(L_DEBUG, "Arranging %p horizontally", container); |
207 | for (i = 0; i < container->children->length; ++i) { | 207 | for (i = 0; i < container->children->length; ++i) { |
208 | swayc_t *child = container->children->items[i]; | 208 | swayc_t *child = container->children->items[i]; |
209 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale); | 209 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); |
210 | child->x = x + container->x; | 210 | child->x = x + container->x; |
211 | child->y = y + container->y; | 211 | child->y = y + container->y; |
212 | arrange_windows(child, child->width * scale, height); | 212 | arrange_windows(child, child->width * scale, height); |
@@ -217,7 +217,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
217 | case L_VERT: | 217 | case L_VERT: |
218 | // Calculate total height | 218 | // Calculate total height |
219 | for (i = 0; i < container->children->length; ++i) { | 219 | for (i = 0; i < container->children->length; ++i) { |
220 | int *old_height = &((swayc_t *)container->children->items[i])->height; | 220 | double *old_height = &((swayc_t *)container->children->items[i])->height; |
221 | if (*old_height <= 0) { | 221 | if (*old_height <= 0) { |
222 | if (container->children->length > 1) { | 222 | if (container->children->length > 1) { |
223 | *old_height = height / (container->children->length - 1); | 223 | *old_height = height / (container->children->length - 1); |
@@ -233,7 +233,7 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
233 | sway_log(L_DEBUG, "Arranging %p vertically", container); | 233 | sway_log(L_DEBUG, "Arranging %p vertically", container); |
234 | for (i = 0; i < container->children->length; ++i) { | 234 | for (i = 0; i < container->children->length; ++i) { |
235 | swayc_t *child = container->children->items[i]; | 235 | swayc_t *child = container->children->items[i]; |
236 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale); | 236 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); |
237 | child->x = x + container->x; | 237 | child->x = x + container->x; |
238 | child->y = y + container->y; | 238 | child->y = y + container->y; |
239 | arrange_windows(child, width, child->height * scale); | 239 | arrange_windows(child, width, child->height * scale); |
@@ -364,3 +364,39 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) | |||
364 | } | 364 | } |
365 | } | 365 | } |
366 | } | 366 | } |
367 | |||
368 | void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) { | ||
369 | int i; | ||
370 | bool layout_match = true; | ||
371 | sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); | ||
372 | if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) { | ||
373 | container->width += amount; | ||
374 | layout_match = container->layout == L_HORIZ; | ||
375 | } else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) { | ||
376 | container->height += amount; | ||
377 | layout_match = container->layout == L_VERT; | ||
378 | } | ||
379 | if (container->type == C_VIEW) { | ||
380 | struct wlc_geometry geometry = { | ||
381 | .origin = { | ||
382 | .x = container->x + container->gaps / 2, | ||
383 | .y = container->y + container->gaps / 2 | ||
384 | }, | ||
385 | .size = { | ||
386 | .w = container->width - container->gaps, | ||
387 | .h = container->height - container->gaps | ||
388 | } | ||
389 | }; | ||
390 | wlc_view_set_geometry(container->handle, edge, &geometry); | ||
391 | return; | ||
392 | } | ||
393 | if (layout_match) { | ||
394 | for (i = 0; i < container->children->length; i++) { | ||
395 | recursive_resize(container->children->items[i], amount/container->children->length, edge); | ||
396 | } | ||
397 | } else { | ||
398 | for (i = 0; i < container->children->length; i++) { | ||
399 | recursive_resize(container->children->items[i], amount, edge); | ||
400 | } | ||
401 | } | ||
402 | } | ||