summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-21 07:12:05 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-21 07:12:05 -0400
commit464b49eda26f6a518bda39a8d07e1d9b0f498897 (patch)
tree7d0c55221b3028c2843da88b41029abac864b4a5 /sway/commands.c
parentMerge pull request #106 from FSMaxB/session-files (diff)
parentFixes to resizing and added in resize lock once boundaries are exceeded (diff)
downloadsway-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/commands.c')
-rw-r--r--sway/commands.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 3ac7f4dd..d1bbdc89 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -421,6 +421,159 @@ static bool cmd_reload(struct sway_config *config, int argc, char **argv) {
421 return true; 421 return true;
422} 422}
423 423
424static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
425 if (!checkarg(argc, "resize", EXPECTED_AT_LEAST, 3)) {
426 return false;
427 }
428 char *end;
429 int amount = (int)strtol(argv[2], &end, 10);
430 if (errno == ERANGE || amount == 0) {
431 errno = 0;
432 return false;
433 }
434 if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) {
435 return false;
436 }
437 if (strcmp(argv[0], "shrink") == 0) {
438 amount *= -1;
439 }
440
441 swayc_t *parent = get_focused_view(active_workspace);
442 swayc_t *focused = parent;
443 swayc_t *sibling;
444 if (!parent) {
445 return true;
446 }
447 // Find the closest parent container which has siblings of the proper layout.
448 // Then apply the resize to all of them.
449 int i;
450 if (strcmp(argv[1], "width") == 0) {
451 int lnumber = 0;
452 int rnumber = 0;
453 while (parent->parent) {
454 if (parent->parent->layout == L_HORIZ) {
455 for (i = 0; i < parent->parent->children->length; i++) {
456 sibling = parent->parent->children->items[i];
457 if (sibling->x != focused->x) {
458 if (sibling->x < parent->x) {
459 lnumber++;
460 } else if (sibling->x > parent->x) {
461 rnumber++;
462 }
463 }
464 }
465 if (rnumber || lnumber) {
466 break;
467 }
468 }
469 parent = parent->parent;
470 }
471 if (parent == &root_container) {
472 return true;
473 }
474 sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber);
475 //TODO: Ensure rounding is done in such a way that there are NO pixel leaks
476 for (i = 0; i < parent->parent->children->length; i++) {
477 sibling = parent->parent->children->items[i];
478 if (sibling->x != focused->x) {
479 if (sibling->x < parent->x) {
480 double pixels = -1 * amount;
481 pixels /= lnumber;
482 if (rnumber) {
483 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT);
484 } else {
485 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT);
486 }
487 } else if (sibling->x > parent->x) {
488 double pixels = -1 * amount;
489 pixels /= rnumber;
490 if (lnumber) {
491 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT);
492 } else {
493 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT);
494 }
495 }
496 } else {
497 if (rnumber != 0 && lnumber != 0) {
498 double pixels = amount;
499 pixels /= 2;
500 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT);
501 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT);
502 } else if (rnumber) {
503 recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT);
504 } else if (lnumber) {
505 recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT);
506 }
507 }
508 }
509 // Recursive resize does not handle positions, let arrange_windows
510 // take care of that.
511 arrange_windows(active_workspace, -1, -1);
512 return true;
513 } else if (strcmp(argv[1], "height") == 0) {
514 int tnumber = 0;
515 int bnumber = 0;
516 while (parent->parent) {
517 if (parent->parent->layout == L_VERT) {
518 for (i = 0; i < parent->parent->children->length; i++) {
519 sibling = parent->parent->children->items[i];
520 if (sibling->y != focused->y) {
521 if (sibling->y < parent->y) {
522 bnumber++;
523 } else if (sibling->y > parent->y) {
524 tnumber++;
525 }
526 }
527 }
528 if (bnumber || tnumber) {
529 break;
530 }
531 }
532 parent = parent->parent;
533 }
534 if (parent == &root_container) {
535 return true;
536 }
537 sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber);
538 //TODO: Ensure rounding is done in such a way that there are NO pixel leaks
539 for (i = 0; i < parent->parent->children->length; i++) {
540 sibling = parent->parent->children->items[i];
541 if (sibling->y != focused->y) {
542 if (sibling->y < parent->y) {
543 double pixels = -1 * amount;
544 pixels /= bnumber;
545 if (tnumber) {
546 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM);
547 } else {
548 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM);
549 }
550 } else if (sibling->x > parent->x) {
551 double pixels = -1 * amount;
552 pixels /= tnumber;
553 if (bnumber) {
554 recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP);
555 } else {
556 recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP);
557 }
558 }
559 } else {
560 if (bnumber != 0 && tnumber != 0) {
561 double pixels = amount/2;
562 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP);
563 recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM);
564 } else if (tnumber) {
565 recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP);
566 } else if (bnumber) {
567 recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM);
568 }
569 }
570 }
571 arrange_windows(active_workspace, -1, -1);
572 return true;
573 }
574 return true;
575}
576
424static bool cmd_set(struct sway_config *config, int argc, char **argv) { 577static bool cmd_set(struct sway_config *config, int argc, char **argv) {
425 if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { 578 if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) {
426 return false; 579 return false;
@@ -584,6 +737,7 @@ static struct cmd_handler handlers[] = {
584 { "layout", cmd_layout }, 737 { "layout", cmd_layout },
585 { "log_colors", cmd_log_colors }, 738 { "log_colors", cmd_log_colors },
586 { "reload", cmd_reload }, 739 { "reload", cmd_reload },
740 { "resize", cmd_resize },
587 { "set", cmd_set }, 741 { "set", cmd_set },
588 { "split", cmd_split }, 742 { "split", cmd_split },
589 { "splith", cmd_splith }, 743 { "splith", cmd_splith },