diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c index 644b8005..cdc80a0b 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -422,6 +422,150 @@ static bool cmd_reload(struct sway_config *config, int argc, char **argv) { | |||
422 | return true; | 422 | return true; |
423 | } | 423 | } |
424 | 424 | ||
425 | static bool cmd_resize(struct sway_config *config, int argc, char **argv) { | ||
426 | if (!checkarg(argc, "resize", EXPECTED_AT_LEAST, 3)) { | ||
427 | return false; | ||
428 | } | ||
429 | char *end; | ||
430 | int amount = (int)strtol(argv[2], &end, 10); | ||
431 | if (errno == ERANGE || amount == 0) { | ||
432 | errno = 0; | ||
433 | return false; | ||
434 | } | ||
435 | if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) { | ||
436 | return false; | ||
437 | } | ||
438 | if (strcmp(argv[0], "shrink") == 0) { | ||
439 | amount *= -1; | ||
440 | } | ||
441 | |||
442 | swayc_t *parent = get_focused_view(active_workspace); | ||
443 | swayc_t *focused = parent; | ||
444 | swayc_t *sibling; | ||
445 | if (!parent) { | ||
446 | return true; | ||
447 | } | ||
448 | // Find the closest possible sibling and resize using that edge | ||
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/lnumber); | ||
481 | if (lnumber) { | ||
482 | recursive_resize(sibling, pixels/2, MOVE_RIGHT); | ||
483 | } else { | ||
484 | recursive_resize(sibling, pixels, MOVE_RIGHT); | ||
485 | } | ||
486 | } else if (sibling->x > parent->x) { | ||
487 | double pixels = -1 * (amount/rnumber); | ||
488 | if (rnumber) { | ||
489 | recursive_resize(sibling, pixels/2, MOVE_LEFT); | ||
490 | } else { | ||
491 | recursive_resize(sibling, pixels, MOVE_LEFT); | ||
492 | } | ||
493 | } | ||
494 | } else { | ||
495 | if (rnumber != 0 && lnumber != 0) { | ||
496 | recursive_resize(parent, amount/2, MOVE_LEFT); | ||
497 | recursive_resize(parent, amount/2, MOVE_RIGHT); | ||
498 | } else if (rnumber) { | ||
499 | recursive_resize(parent, amount, MOVE_RIGHT); | ||
500 | } else if (lnumber) { | ||
501 | recursive_resize(parent, amount, MOVE_LEFT); | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | arrange_windows(active_workspace, -1, -1); | ||
506 | return true; | ||
507 | } else if (strcmp(argv[1], "height") == 0) { | ||
508 | int tnumber = 0; | ||
509 | int bnumber = 0; | ||
510 | while (parent->parent) { | ||
511 | if (parent->parent->layout == L_VERT) { | ||
512 | for (i = 0; i < parent->parent->children->length; i++) { | ||
513 | sibling = parent->parent->children->items[i]; | ||
514 | if (sibling->y != focused->y) { | ||
515 | if (sibling->y < parent->y) { | ||
516 | bnumber++; | ||
517 | } else if (sibling->y > parent->y) { | ||
518 | tnumber++; | ||
519 | } | ||
520 | } | ||
521 | } | ||
522 | if (bnumber || tnumber) { | ||
523 | break; | ||
524 | } | ||
525 | } | ||
526 | parent = parent->parent; | ||
527 | } | ||
528 | if (parent == &root_container) { | ||
529 | return true; | ||
530 | } | ||
531 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); | ||
532 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | ||
533 | for (i = 0; i < parent->parent->children->length; i++) { | ||
534 | sibling = parent->parent->children->items[i]; | ||
535 | if (sibling->y != focused->y) { | ||
536 | if (sibling->y < parent->y) { | ||
537 | double pixels = -1 * (amount/bnumber); | ||
538 | if (tnumber) { | ||
539 | recursive_resize(sibling, pixels/2, MOVE_UP); | ||
540 | } else { | ||
541 | recursive_resize(sibling, pixels, MOVE_UP); | ||
542 | } | ||
543 | } else if (sibling->x > parent->x) { | ||
544 | double pixels = -1 * (amount/tnumber); | ||
545 | if (bnumber) { | ||
546 | recursive_resize(sibling, pixels/2, MOVE_DOWN); | ||
547 | } else { | ||
548 | recursive_resize(sibling, pixels, MOVE_DOWN); | ||
549 | } | ||
550 | } | ||
551 | } else { | ||
552 | if (bnumber != 0 && tnumber != 0) { | ||
553 | recursive_resize(parent, amount/2, MOVE_UP); | ||
554 | recursive_resize(parent, amount/2, MOVE_DOWN); | ||
555 | } else if (tnumber) { | ||
556 | recursive_resize(parent, amount, MOVE_UP); | ||
557 | } else if (bnumber) { | ||
558 | recursive_resize(parent, amount, MOVE_DOWN); | ||
559 | } | ||
560 | } | ||
561 | } | ||
562 | arrange_windows(active_workspace, -1, -1); | ||
563 | return true; | ||
564 | } | ||
565 | sway_log(L_INFO, "Done with resize"); | ||
566 | return true; | ||
567 | } | ||
568 | |||
425 | static bool cmd_set(struct sway_config *config, int argc, char **argv) { | 569 | static bool cmd_set(struct sway_config *config, int argc, char **argv) { |
426 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { | 570 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { |
427 | return false; | 571 | return false; |
@@ -587,6 +731,7 @@ static struct cmd_handler handlers[] = { | |||
587 | { "layout", cmd_layout }, | 731 | { "layout", cmd_layout }, |
588 | { "log_colors", cmd_log_colors }, | 732 | { "log_colors", cmd_log_colors }, |
589 | { "reload", cmd_reload }, | 733 | { "reload", cmd_reload }, |
734 | { "resize", cmd_resize }, | ||
590 | { "set", cmd_set }, | 735 | { "set", cmd_set }, |
591 | { "split", cmd_split }, | 736 | { "split", cmd_split }, |
592 | { "splith", cmd_splith }, | 737 | { "splith", cmd_splith }, |