summaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index ad659ef5..99e9dbda 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -10,6 +10,7 @@
10#include "sway/commands.h" 10#include "sway/commands.h"
11#include "sway/tree/arrange.h" 11#include "sway/tree/arrange.h"
12#include "sway/tree/view.h" 12#include "sway/tree/view.h"
13#include "sway/tree/workspace.h"
13#include "log.h" 14#include "log.h"
14 15
15static const int MIN_SANE_W = 100, MIN_SANE_H = 60; 16static const int MIN_SANE_W = 100, MIN_SANE_H = 60;
@@ -75,7 +76,7 @@ static int parse_resize_amount(int argc, char **argv,
75 76
76static void calculate_constraints(int *min_width, int *max_width, 77static void calculate_constraints(int *min_width, int *max_width,
77 int *min_height, int *max_height) { 78 int *min_height, int *max_height) {
78 struct sway_container *con = config->handler_context.current_container; 79 struct sway_container *con = config->handler_context.container;
79 80
80 if (config->floating_minimum_width == -1) { // no minimum 81 if (config->floating_minimum_width == -1) { // no minimum
81 *min_width = 0; 82 *min_width = 0;
@@ -96,8 +97,7 @@ static void calculate_constraints(int *min_width, int *max_width,
96 if (config->floating_maximum_width == -1) { // no maximum 97 if (config->floating_maximum_width == -1) { // no maximum
97 *max_width = INT_MAX; 98 *max_width = INT_MAX;
98 } else if (config->floating_maximum_width == 0) { // automatic 99 } else if (config->floating_maximum_width == 0) { // automatic
99 struct sway_container *ws = container_parent(con, C_WORKSPACE); 100 *max_width = con->workspace->width;
100 *max_width = ws->width;
101 } else { 101 } else {
102 *max_width = config->floating_maximum_width; 102 *max_width = config->floating_maximum_width;
103 } 103 }
@@ -105,8 +105,7 @@ static void calculate_constraints(int *min_width, int *max_width,
105 if (config->floating_maximum_height == -1) { // no maximum 105 if (config->floating_maximum_height == -1) { // no maximum
106 *max_height = INT_MAX; 106 *max_height = INT_MAX;
107 } else if (config->floating_maximum_height == 0) { // automatic 107 } else if (config->floating_maximum_height == 0) { // automatic
108 struct sway_container *ws = container_parent(con, C_WORKSPACE); 108 *max_height = con->workspace->height;
109 *max_height = ws->height;
110 } else { 109 } else {
111 *max_height = config->floating_maximum_height; 110 *max_height = config->floating_maximum_height;
112 } 111 }
@@ -191,11 +190,11 @@ static void resize_tiled(struct sway_container *parent, int amount,
191 normalize_axis(axis) == RESIZE_AXIS_HORIZONTAL ? L_HORIZ : L_VERT; 190 normalize_axis(axis) == RESIZE_AXIS_HORIZONTAL ? L_HORIZ : L_VERT;
192 int minor_weight = 0; 191 int minor_weight = 0;
193 int major_weight = 0; 192 int major_weight = 0;
194 while (parent->parent) { 193 while (parent) {
195 struct sway_container *next = parent->parent; 194 list_t *siblings = container_get_siblings(parent);
196 if (next->layout == parallel_layout) { 195 if (container_parent_layout(parent) == parallel_layout) {
197 for (int i = 0; i < next->children->length; i++) { 196 for (int i = 0; i < siblings->length; i++) {
198 struct sway_container *sibling = next->children->items[i]; 197 struct sway_container *sibling = siblings->items[i];
199 198
200 int sibling_pos = parallel_coord(sibling, axis); 199 int sibling_pos = parallel_coord(sibling, axis);
201 int focused_pos = parallel_coord(focused, axis); 200 int focused_pos = parallel_coord(focused, axis);
@@ -213,17 +212,13 @@ static void resize_tiled(struct sway_container *parent, int amount,
213 break; 212 break;
214 } 213 }
215 } 214 }
216 parent = next; 215 parent = parent->parent;
217 } 216 }
218 217 if (!parent) {
219 if (parent->type == C_ROOT) { 218 // Can't resize in this direction
220 return; 219 return;
221 } 220 }
222 221
223 wlr_log(WLR_DEBUG,
224 "Found the proper parent: %p. It has %d l conts, and %d r conts",
225 parent->parent, minor_weight, major_weight);
226
227 // Implement up/down/left/right direction by zeroing one of the weights, 222 // Implement up/down/left/right direction by zeroing one of the weights,
228 // then setting the axis to be horizontal or vertical 223 // then setting the axis to be horizontal or vertical
229 if (axis == RESIZE_AXIS_UP || axis == RESIZE_AXIS_LEFT) { 224 if (axis == RESIZE_AXIS_UP || axis == RESIZE_AXIS_LEFT) {
@@ -237,9 +232,10 @@ static void resize_tiled(struct sway_container *parent, int amount,
237 232
238 //TODO: Ensure rounding is done in such a way that there are NO pixel leaks 233 //TODO: Ensure rounding is done in such a way that there are NO pixel leaks
239 // ^ ????? 234 // ^ ?????
235 list_t *siblings = container_get_siblings(parent);
240 236
241 for (int i = 0; i < parent->parent->children->length; i++) { 237 for (int i = 0; i < siblings->length; i++) {
242 struct sway_container *sibling = parent->parent->children->items[i]; 238 struct sway_container *sibling = siblings->items[i];
243 239
244 int sibling_pos = parallel_coord(sibling, axis); 240 int sibling_pos = parallel_coord(sibling, axis);
245 int focused_pos = parallel_coord(focused, axis); 241 int focused_pos = parallel_coord(focused, axis);
@@ -277,8 +273,8 @@ static void resize_tiled(struct sway_container *parent, int amount,
277 enum wlr_edges major_edge = axis == RESIZE_AXIS_HORIZONTAL ? 273 enum wlr_edges major_edge = axis == RESIZE_AXIS_HORIZONTAL ?
278 WLR_EDGE_RIGHT : WLR_EDGE_BOTTOM; 274 WLR_EDGE_RIGHT : WLR_EDGE_BOTTOM;
279 275
280 for (int i = 0; i < parent->parent->children->length; i++) { 276 for (int i = 0; i < siblings->length; i++) {
281 struct sway_container *sibling = parent->parent->children->items[i]; 277 struct sway_container *sibling = siblings->items[i];
282 278
283 int sibling_pos = parallel_coord(sibling, axis); 279 int sibling_pos = parallel_coord(sibling, axis);
284 int focused_pos = parallel_coord(focused, axis); 280 int focused_pos = parallel_coord(focused, axis);
@@ -316,7 +312,11 @@ static void resize_tiled(struct sway_container *parent, int amount,
316 } 312 }
317 } 313 }
318 314
319 arrange_windows(parent->parent); 315 if (parent->parent) {
316 arrange_container(parent->parent);
317 } else {
318 arrange_workspace(parent->workspace);
319 }
320} 320}
321 321
322void container_resize_tiled(struct sway_container *parent, 322void container_resize_tiled(struct sway_container *parent,
@@ -346,7 +346,7 @@ void container_resize_tiled(struct sway_container *parent,
346 */ 346 */
347static struct cmd_results *resize_adjust_floating(enum resize_axis axis, 347static struct cmd_results *resize_adjust_floating(enum resize_axis axis,
348 struct resize_amount *amount) { 348 struct resize_amount *amount) {
349 struct sway_container *con = config->handler_context.current_container; 349 struct sway_container *con = config->handler_context.container;
350 int grow_width = 0, grow_height = 0; 350 int grow_width = 0, grow_height = 0;
351 switch (axis) { 351 switch (axis) {
352 case RESIZE_AXIS_HORIZONTAL: 352 case RESIZE_AXIS_HORIZONTAL:
@@ -400,15 +400,15 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis,
400 con->width += grow_width; 400 con->width += grow_width;
401 con->height += grow_height; 401 con->height += grow_height;
402 402
403 if (con->type == C_VIEW) { 403 if (con->view) {
404 struct sway_view *view = con->sway_view; 404 struct sway_view *view = con->view;
405 view->x += grow_x; 405 view->x += grow_x;
406 view->y += grow_y; 406 view->y += grow_y;
407 view->width += grow_width; 407 view->width += grow_width;
408 view->height += grow_height; 408 view->height += grow_height;
409 } 409 }
410 410
411 arrange_windows(con); 411 arrange_container(con);
412 412
413 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 413 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
414} 414}
@@ -418,7 +418,7 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis,
418 */ 418 */
419static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, 419static struct cmd_results *resize_adjust_tiled(enum resize_axis axis,
420 struct resize_amount *amount) { 420 struct resize_amount *amount) {
421 struct sway_container *current = config->handler_context.current_container; 421 struct sway_container *current = config->handler_context.container;
422 422
423 if (amount->unit == RESIZE_UNIT_DEFAULT) { 423 if (amount->unit == RESIZE_UNIT_DEFAULT) {
424 amount->unit = RESIZE_UNIT_PPT; 424 amount->unit = RESIZE_UNIT_PPT;
@@ -456,13 +456,15 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con,
456 width->unit == RESIZE_UNIT_DEFAULT) { 456 width->unit == RESIZE_UNIT_DEFAULT) {
457 // Convert to px 457 // Convert to px
458 struct sway_container *parent = con->parent; 458 struct sway_container *parent = con->parent;
459 while (parent->type >= C_WORKSPACE && parent->layout != L_HORIZ) { 459 while (parent && parent->layout != L_HORIZ) {
460 parent = parent->parent; 460 parent = parent->parent;
461 } 461 }
462 if (parent->type >= C_WORKSPACE) { 462 if (parent) {
463 width->amount = parent->width * width->amount / 100; 463 width->amount = parent->width * width->amount / 100;
464 width->unit = RESIZE_UNIT_PX; 464 } else {
465 width->amount = con->workspace->width * width->amount / 100;
465 } 466 }
467 width->unit = RESIZE_UNIT_PX;
466 } 468 }
467 if (width->unit == RESIZE_UNIT_PX) { 469 if (width->unit == RESIZE_UNIT_PX) {
468 resize_tiled(con, width->amount - con->width, 470 resize_tiled(con, width->amount - con->width,
@@ -475,13 +477,15 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con,
475 height->unit == RESIZE_UNIT_DEFAULT) { 477 height->unit == RESIZE_UNIT_DEFAULT) {
476 // Convert to px 478 // Convert to px
477 struct sway_container *parent = con->parent; 479 struct sway_container *parent = con->parent;
478 while (parent->type >= C_WORKSPACE && parent->layout != L_VERT) { 480 while (parent && parent->layout != L_VERT) {
479 parent = parent->parent; 481 parent = parent->parent;
480 } 482 }
481 if (parent->type >= C_WORKSPACE) { 483 if (parent) {
482 height->amount = parent->height * height->amount / 100; 484 height->amount = parent->height * height->amount / 100;
483 height->unit = RESIZE_UNIT_PX; 485 } else {
486 height->amount = con->workspace->height * height->amount / 100;
484 } 487 }
488 height->unit = RESIZE_UNIT_PX;
485 } 489 }
486 if (height->unit == RESIZE_UNIT_PX) { 490 if (height->unit == RESIZE_UNIT_PX) {
487 resize_tiled(con, height->amount - con->height, 491 resize_tiled(con, height->amount - con->height,
@@ -508,15 +512,15 @@ static struct cmd_results *resize_set_floating(struct sway_container *con,
508 con->width = width->amount; 512 con->width = width->amount;
509 con->height = height->amount; 513 con->height = height->amount;
510 514
511 if (con->type == C_VIEW) { 515 if (con->view) {
512 struct sway_view *view = con->sway_view; 516 struct sway_view *view = con->view;
513 view->x -= grow_width / 2; 517 view->x -= grow_width / 2;
514 view->y -= grow_height / 2; 518 view->y -= grow_height / 2;
515 view->width += grow_width; 519 view->width += grow_width;
516 view->height += grow_height; 520 view->height += grow_height;
517 } 521 }
518 522
519 arrange_windows(con); 523 arrange_container(con);
520 524
521 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 525 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
522} 526}
@@ -555,7 +559,7 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) {
555 } 559 }
556 560
557 // If 0, don't resize that dimension 561 // If 0, don't resize that dimension
558 struct sway_container *con = config->handler_context.current_container; 562 struct sway_container *con = config->handler_context.container;
559 if (width.amount <= 0) { 563 if (width.amount <= 0) {
560 width.amount = con->width; 564 width.amount = con->width;
561 } 565 }
@@ -624,7 +628,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
624 first_amount.amount *= multiplier; 628 first_amount.amount *= multiplier;
625 second_amount.amount *= multiplier; 629 second_amount.amount *= multiplier;
626 630
627 struct sway_container *con = config->handler_context.current_container; 631 struct sway_container *con = config->handler_context.container;
628 if (container_is_floating(con)) { 632 if (container_is_floating(con)) {
629 // Floating containers can only resize in px. Choose an amount which 633 // Floating containers can only resize in px. Choose an amount which
630 // uses px, with fallback to an amount that specified no unit. 634 // uses px, with fallback to an amount that specified no unit.
@@ -657,14 +661,10 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
657} 661}
658 662
659struct cmd_results *cmd_resize(int argc, char **argv) { 663struct cmd_results *cmd_resize(int argc, char **argv) {
660 struct sway_container *current = config->handler_context.current_container; 664 struct sway_container *current = config->handler_context.container;
661 if (!current) { 665 if (!current) {
662 return cmd_results_new(CMD_INVALID, "resize", "Cannot resize nothing"); 666 return cmd_results_new(CMD_INVALID, "resize", "Cannot resize nothing");
663 } 667 }
664 if (current->type != C_VIEW && current->type != C_CONTAINER) {
665 return cmd_results_new(CMD_INVALID, "resize",
666 "Can only resize views/containers");
667 }
668 668
669 struct cmd_results *error; 669 struct cmd_results *error;
670 if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { 670 if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) {