summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c225
1 files changed, 6 insertions, 219 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 36299c8d..62794111 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -16,6 +16,7 @@
16#include "container.h" 16#include "container.h"
17#include "handlers.h" 17#include "handlers.h"
18#include "sway.h" 18#include "sway.h"
19#include "resize.h"
19 20
20struct modifier_key { 21struct modifier_key {
21 char *name; 22 char *name;
@@ -448,240 +449,26 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
448 return false; 449 return false;
449 } 450 }
450 char *end; 451 char *end;
451 int min_sane_w = 100;
452 int min_sane_h = 60;
453 int amount = (int)strtol(argv[2], &end, 10); 452 int amount = (int)strtol(argv[2], &end, 10);
454 if (errno == ERANGE || amount == 0) { 453 if (errno == ERANGE || amount == 0) {
455 errno = 0; 454 errno = 0;
456 return false; 455 return false;
457 } 456 }
457
458 if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) { 458 if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) {
459 return false; 459 return false;
460 } 460 }
461
461 if (strcmp(argv[0], "shrink") == 0) { 462 if (strcmp(argv[0], "shrink") == 0) {
462 amount *= -1; 463 amount *= -1;
463 } 464 }
464 465
465 swayc_t *parent = get_focused_view(swayc_active_workspace());
466 swayc_t *focused = parent;
467 swayc_t *sibling;
468 if (!parent) {
469 return true;
470 }
471 // Find the closest parent container which has siblings of the proper layout.
472 // Then apply the resize to all of them.
473 int i;
474 if (strcmp(argv[1], "width") == 0) { 466 if (strcmp(argv[1], "width") == 0) {
475 int lnumber = 0; 467 return resize_tiled(amount, true);
476 int rnumber = 0;
477 while (parent->parent) {
478 if (parent->parent->layout == L_HORIZ) {
479 for (i = 0; i < parent->parent->children->length; i++) {
480 sibling = parent->parent->children->items[i];
481 if (sibling->x != focused->x) {
482 if (sibling->x < parent->x) {
483 lnumber++;
484 } else if (sibling->x > parent->x) {
485 rnumber++;
486 }
487 }
488 }
489 if (rnumber || lnumber) {
490 break;
491 }
492 }
493 parent = parent->parent;
494 }
495 if (parent == &root_container) {
496 return true;
497 }
498 sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber);
499 //TODO: Ensure rounding is done in such a way that there are NO pixel leaks
500 bool valid = true;
501 for (i = 0; i < parent->parent->children->length; i++) {
502 sibling = parent->parent->children->items[i];
503 if (sibling->x != focused->x) {
504 if (sibling->x < parent->x) {
505 double pixels = -1 * amount;
506 pixels /= lnumber;
507 if (rnumber) {
508 if ((sibling->width + pixels/2) < min_sane_w) {
509 valid = false;
510 break;
511 }
512 } else {
513 if ((sibling->width + pixels) < min_sane_w) {
514 valid = false;
515 break;
516 }
517 }
518 } else if (sibling->x > parent->x) {
519 double pixels = -1 * amount;
520 pixels /= rnumber;
521 if (lnumber) {
522 if ((sibling->width + pixels/2) < min_sane_w) {
523 valid = false;
524 break;
525 }
526 } else {
527 if ((sibling->width + pixels) < min_sane_w) {
528 valid = false;
529 break;
530 }
531 }
532 }
533 } else {
534 double pixels = amount;
535 if (parent->width + pixels < min_sane_w) {
536 valid = false;
537 break;
538 }
539 }
540 }
541 if (valid) {
542 for (i = 0; i < parent->parent->children->length; i++) {
543 sibling = parent->parent->children->items[i];
544 if (sibling->x != focused->x) {
545 if (sibling->x < parent->x) {
546 double pixels = -1 * amount;
547 pixels /= lnumber;
548 if (rnumber) {
549 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT);
550 } else {
551 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT);
552 }
553 } else if (sibling->x > parent->x) {
554 double pixels = -1 * amount;
555 pixels /= rnumber;
556 if (lnumber) {
557 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT);
558 } else {
559 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT);
560 }
561 }
562 } else {
563 if (rnumber != 0 && lnumber != 0) {
564 double pixels = amount;
565 pixels /= 2;
566 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT);
567 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT);
568 } else if (rnumber) {
569 recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT);
570 } else if (lnumber) {
571 recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT);
572 }
573 }
574 }
575 // Recursive resize does not handle positions, let arrange_windows
576 // take care of that.
577 arrange_windows(swayc_active_workspace(), -1, -1);
578 }
579 return true;
580 } else if (strcmp(argv[1], "height") == 0) { 468 } else if (strcmp(argv[1], "height") == 0) {
581 int tnumber = 0; 469 return resize_tiled(amount, false);
582 int bnumber = 0;
583 while (parent->parent) {
584 if (parent->parent->layout == L_VERT) {
585 for (i = 0; i < parent->parent->children->length; i++) {
586 sibling = parent->parent->children->items[i];
587 if (sibling->y != focused->y) {
588 if (sibling->y < parent->y) {
589 bnumber++;
590 } else if (sibling->y > parent->y) {
591 tnumber++;
592 }
593 }
594 }
595 if (bnumber || tnumber) {
596 break;
597 }
598 }
599 parent = parent->parent;
600 }
601 if (parent == &root_container) {
602 return true;
603 }
604 sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber);
605 //TODO: Ensure rounding is done in such a way that there are NO pixel leaks
606 bool valid = true;
607 for (i = 0; i < parent->parent->children->length; i++) {
608 sibling = parent->parent->children->items[i];
609 if (sibling->y != focused->y) {
610 if (sibling->y < parent->y) {
611 double pixels = -1 * amount;
612 pixels /= bnumber;
613 if (tnumber) {
614 if ((sibling->height + pixels/2) < min_sane_h) {
615 valid = false;
616 break;
617 }
618 } else {
619 if ((sibling->height + pixels) < min_sane_h) {
620 valid = false;
621 break;
622 }
623 }
624 } else if (sibling->y > parent->y) {
625 double pixels = -1 * amount;
626 pixels /= tnumber;
627 if (bnumber) {
628 if ((sibling->height + pixels/2) < min_sane_h) {
629 valid = false;
630 break;
631 }
632 } else {
633 if ((sibling->height + pixels) < min_sane_h) {
634 valid = false;
635 break;
636 }
637 }
638 }
639 } else {
640 double pixels = amount;
641 if (parent->height + pixels < min_sane_h) {
642 valid = false;
643 break;
644 }
645 }
646 }
647 if (valid) {
648 for (i = 0; i < parent->parent->children->length; i++) {
649 sibling = parent->parent->children->items[i];
650 if (sibling->y != focused->y) {
651 if (sibling->y < parent->y) {
652 double pixels = -1 * amount;
653 pixels /= bnumber;
654 if (tnumber) {
655 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM);
656 } else {
657 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM);
658 }
659 } else if (sibling->x > parent->x) {
660 double pixels = -1 * amount;
661 pixels /= tnumber;
662 if (bnumber) {
663 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP);
664 } else {
665 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP);
666 }
667 }
668 } else {
669 if (bnumber != 0 && tnumber != 0) {
670 double pixels = amount/2;
671 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP);
672 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM);
673 } else if (tnumber) {
674 recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP);
675 } else if (bnumber) {
676 recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM);
677 }
678 }
679 }
680 arrange_windows(swayc_active_workspace(), -1, -1);
681 }
682 return true;
683 } 470 }
684 return true; 471 return false;
685} 472}
686 473
687static bool cmd_set(struct sway_config *config, int argc, char **argv) { 474static bool cmd_set(struct sway_config *config, int argc, char **argv) {