summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-20 21:37:59 -0500
committerLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-20 21:37:59 -0500
commitf589731f2912660bab6fdffc14ddcdbac3edd41c (patch)
treecda490ea65181959c777e623cb0f20f055f1d90a
parentStyle fixes (diff)
downloadsway-f589731f2912660bab6fdffc14ddcdbac3edd41c.tar.gz
sway-f589731f2912660bab6fdffc14ddcdbac3edd41c.tar.zst
sway-f589731f2912660bab6fdffc14ddcdbac3edd41c.zip
Rewrite of resize command to make it more sane
-rw-r--r--include/container.h4
-rw-r--r--include/layout.h2
-rw-r--r--sway/commands.c53
-rw-r--r--sway/layout.c44
-rw-r--r--sway/log.c4
5 files changed, 60 insertions, 47 deletions
diff --git a/include/container.h b/include/container.h
index bd92058d..d3026011 100644
--- a/include/container.h
+++ b/include/container.h
@@ -33,12 +33,12 @@ struct sway_container {
33 enum swayc_layouts layout; 33 enum swayc_layouts layout;
34 34
35 // Not including borders or margins 35 // Not including borders or margins
36 int width, height; 36 double width, height;
37 37
38 // Used for setting floating geometry 38 // Used for setting floating geometry
39 int desired_width, desired_height; 39 int desired_width, desired_height;
40 40
41 int x, y; 41 double x, y;
42 42
43 bool visible; 43 bool visible;
44 bool is_floating; 44 bool is_floating;
diff --git a/include/layout.h b/include/layout.h
index 4dff81b7..566e3246 100644
--- a/include/layout.h
+++ b/include/layout.h
@@ -29,6 +29,6 @@ swayc_t *get_focused_container(swayc_t *parent);
29swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); 29swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent);
30swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); 30swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir);
31 31
32void recursive_resize(swayc_t *container, double amount, enum movement_direction dir); 32void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge);
33 33
34#endif 34#endif
diff --git a/sway/commands.c b/sway/commands.c
index 27dbb44b..0f743b4e 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -478,31 +478,37 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
478 sibling = parent->parent->children->items[i]; 478 sibling = parent->parent->children->items[i];
479 if (sibling->x != focused->x) { 479 if (sibling->x != focused->x) {
480 if (sibling->x < parent->x) { 480 if (sibling->x < parent->x) {
481 double pixels = -1 * (amount/lnumber); 481 double pixels = -1 * amount;
482 if (lnumber) { 482 pixels /= lnumber;
483 recursive_resize(sibling, pixels/2, MOVE_RIGHT); 483 if (rnumber) {
484 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT);
484 } else { 485 } else {
485 recursive_resize(sibling, pixels, MOVE_RIGHT); 486 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT);
486 } 487 }
487 } else if (sibling->x > parent->x) { 488 } else if (sibling->x > parent->x) {
488 double pixels = -1 * (amount/rnumber); 489 double pixels = -1 * amount;
489 if (rnumber) { 490 pixels /= rnumber;
490 recursive_resize(sibling, pixels/2, MOVE_LEFT); 491 if (lnumber) {
492 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT);
491 } else { 493 } else {
492 recursive_resize(sibling, pixels, MOVE_LEFT); 494 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT);
493 } 495 }
494 } 496 }
495 } else { 497 } else {
496 if (rnumber != 0 && lnumber != 0) { 498 if (rnumber != 0 && lnumber != 0) {
497 recursive_resize(parent, amount/2, MOVE_LEFT); 499 double pixels = amount;
498 recursive_resize(parent, amount/2, MOVE_RIGHT); 500 pixels /= 2;
501 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT);
502 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT);
499 } else if (rnumber) { 503 } else if (rnumber) {
500 recursive_resize(parent, amount, MOVE_RIGHT); 504 recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT);
501 } else if (lnumber) { 505 } else if (lnumber) {
502 recursive_resize(parent, amount, MOVE_LEFT); 506 recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT);
503 } 507 }
504 } 508 }
505 } 509 }
510 // Recursive resize does not handle positions, let arrange_windows
511 // take care of that.
506 arrange_windows(active_workspace, -1, -1); 512 arrange_windows(active_workspace, -1, -1);
507 return true; 513 return true;
508 } else if (strcmp(argv[1], "height") == 0) { 514 } else if (strcmp(argv[1], "height") == 0) {
@@ -535,28 +541,31 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
535 sibling = parent->parent->children->items[i]; 541 sibling = parent->parent->children->items[i];
536 if (sibling->y != focused->y) { 542 if (sibling->y != focused->y) {
537 if (sibling->y < parent->y) { 543 if (sibling->y < parent->y) {
538 double pixels = -1 * (amount/bnumber); 544 double pixels = -1 * amount;
545 pixels /= bnumber;
539 if (tnumber) { 546 if (tnumber) {
540 recursive_resize(sibling, pixels/2, MOVE_UP); 547 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM);
541 } else { 548 } else {
542 recursive_resize(sibling, pixels, MOVE_UP); 549 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM);
543 } 550 }
544 } else if (sibling->x > parent->x) { 551 } else if (sibling->x > parent->x) {
545 double pixels = -1 * (amount/tnumber); 552 double pixels = -1 * amount;
553 pixels /= tnumber;
546 if (bnumber) { 554 if (bnumber) {
547 recursive_resize(sibling, pixels/2, MOVE_DOWN); 555 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP);
548 } else { 556 } else {
549 recursive_resize(sibling, pixels, MOVE_DOWN); 557 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP);
550 } 558 }
551 } 559 }
552 } else { 560 } else {
553 if (bnumber != 0 && tnumber != 0) { 561 if (bnumber != 0 && tnumber != 0) {
554 recursive_resize(parent, amount/2, MOVE_UP); 562 double pixels = amount/2;
555 recursive_resize(parent, amount/2, MOVE_DOWN); 563 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP);
564 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM);
556 } else if (tnumber) { 565 } else if (tnumber) {
557 recursive_resize(parent, amount, MOVE_UP); 566 recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP);
558 } else if (bnumber) { 567 } else if (bnumber) {
559 recursive_resize(parent, amount, MOVE_DOWN); 568 recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM);
560 } 569 }
561 } 570 }
562 } 571 }
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
31void add_child(swayc_t *parent, swayc_t *child) { 31void 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
42void add_floating(swayc_t *ws, swayc_t *child) { 42void 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
374void recursive_resize(swayc_t *container, double amount, enum movement_direction dir) { 374void 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}
diff --git a/sway/log.c b/sway/log.c
index 6e01421b..eda0c88e 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -142,8 +142,8 @@ static void container_log(const swayc_t *c) {
142 c->layout == L_STACKED ? "Stacked|": 142 c->layout == L_STACKED ? "Stacked|":
143 c->layout == L_FLOATING ? "Floating|": 143 c->layout == L_FLOATING ? "Floating|":
144 "Unknown|"); 144 "Unknown|");
145 fprintf(stderr, "w:%d|h:%d|", c->width, c->height); 145 fprintf(stderr, "w:%f|h:%f|", c->width, c->height);
146 fprintf(stderr, "x:%d|y:%d|", c->x, c->y); 146 fprintf(stderr, "x:%f|y:%f|", c->x, c->y);
147 fprintf(stderr, "vis:%c|", c->visible?'t':'f'); 147 fprintf(stderr, "vis:%c|", c->visible?'t':'f');
148 fprintf(stderr, "name:%.16s|", c->name); 148 fprintf(stderr, "name:%.16s|", c->name);
149 fprintf(stderr, "children:%d\n",c->children?c->children->length:0); 149 fprintf(stderr, "children:%d\n",c->children?c->children->length:0);