diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 131 |
1 files changed, 118 insertions, 13 deletions
diff --git a/sway/commands.c b/sway/commands.c index 0fc98538..ffe7faa4 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -517,9 +517,10 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | |||
517 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { | 517 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { |
518 | return false; | 518 | return false; |
519 | } | 519 | } |
520 | 520 | const char *amount_str = argv[0]; | |
521 | if (argc == 1) { | 521 | // gaps amount |
522 | int amount = (int)strtol(argv[0], NULL, 10); | 522 | if (argc >= 1 && isdigit(*amount_str)) { |
523 | int amount = (int)strtol(amount_str, NULL, 10); | ||
523 | if (errno == ERANGE || amount == 0) { | 524 | if (errno == ERANGE || amount == 0) { |
524 | errno = 0; | 525 | errno = 0; |
525 | return false; | 526 | return false; |
@@ -530,23 +531,127 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | |||
530 | if (config->gaps_outer == 0) { | 531 | if (config->gaps_outer == 0) { |
531 | config->gaps_outer = amount; | 532 | config->gaps_outer = amount; |
532 | } | 533 | } |
533 | } else if (argc == 2) { | 534 | return true; |
534 | int amount = (int)strtol(argv[1], NULL, 10); | 535 | } |
536 | // gaps inner|outer n | ||
537 | else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { | ||
538 | int amount = (int)strtol(amount_str, NULL, 10); | ||
535 | if (errno == ERANGE || amount == 0) { | 539 | if (errno == ERANGE || amount == 0) { |
536 | errno = 0; | 540 | errno = 0; |
537 | return false; | 541 | return false; |
538 | } | 542 | } |
539 | if (strcasecmp(argv[0], "inner") == 0) { | 543 | const char *target_str = argv[0]; |
544 | if (strcasecmp(target_str, "inner") == 0) { | ||
540 | config->gaps_inner = amount; | 545 | config->gaps_inner = amount; |
541 | } else if (strcasecmp(argv[0], "outer") == 0) { | 546 | } else if (strcasecmp(target_str, "outer") == 0) { |
542 | config->gaps_outer = amount; | 547 | config->gaps_outer = amount; |
548 | } | ||
549 | return true; | ||
550 | } | ||
551 | // gaps inner|outer current|all set|plus|minus n | ||
552 | if (argc < 4) { | ||
553 | return false; | ||
554 | } | ||
555 | // gaps inner|outer ... | ||
556 | const char *inout_str = argv[0]; | ||
557 | enum {INNER, OUTER} inout; | ||
558 | if (strcasecmp(inout_str, "inner") == 0) { | ||
559 | inout = INNER; | ||
560 | } else if (strcasecmp(inout_str, "outer") == 0) { | ||
561 | inout = OUTER; | ||
562 | } else { | ||
563 | return false; | ||
564 | } | ||
565 | |||
566 | // gaps ... current|all ... | ||
567 | const char *target_str = argv[1]; | ||
568 | enum {CURRENT, WORKSPACE, ALL} target; | ||
569 | if (strcasecmp(target_str, "current") == 0) { | ||
570 | target = CURRENT; | ||
571 | } else if (strcasecmp(target_str, "all") == 0) { | ||
572 | target = ALL; | ||
573 | } else if (strcasecmp(target_str, "workspace") == 0){ | ||
574 | if (inout == OUTER) { | ||
575 | target = CURRENT; | ||
543 | } else { | 576 | } else { |
544 | return false; | 577 | // Set gap for views in workspace |
578 | target = WORKSPACE; | ||
545 | } | 579 | } |
546 | } else { | 580 | } else { |
547 | return false; | 581 | return false; |
548 | } | 582 | } |
549 | arrange_windows(&root_container, -1, -1); | 583 | |
584 | // gaps ... n | ||
585 | amount_str = argv[3]; | ||
586 | int amount = (int)strtol(amount_str, NULL, 10); | ||
587 | if (errno == ERANGE || amount == 0) { | ||
588 | errno = 0; | ||
589 | return false; | ||
590 | } | ||
591 | |||
592 | // gaps ... set|plus|minus ... | ||
593 | const char *method_str = argv[2]; | ||
594 | enum {SET, ADD} method; | ||
595 | if (strcasecmp(method_str, "set") == 0) { | ||
596 | method = SET; | ||
597 | } else if (strcasecmp(method_str, "plus") == 0) { | ||
598 | method = ADD; | ||
599 | } else if (strcasecmp(method_str, "minus") == 0) { | ||
600 | method = ADD; | ||
601 | amount *= -1; | ||
602 | } else { | ||
603 | return false; | ||
604 | } | ||
605 | |||
606 | if (target == CURRENT) { | ||
607 | swayc_t *cont; | ||
608 | if (inout == OUTER) { | ||
609 | if ((cont = swayc_active_workspace()) == NULL) { | ||
610 | return false; | ||
611 | } | ||
612 | } else { | ||
613 | if ((cont = get_focused_view(&root_container))->type != C_VIEW) { | ||
614 | return false; | ||
615 | } | ||
616 | } | ||
617 | cont->gaps = swayc_gap(cont); | ||
618 | if (method == SET) { | ||
619 | cont->gaps = amount; | ||
620 | } else if ((cont->gaps += amount) < 0) { | ||
621 | cont->gaps = 0; | ||
622 | } | ||
623 | arrange_windows(cont->parent, -1, -1); | ||
624 | } else if (inout == OUTER) { | ||
625 | //resize all workspace. | ||
626 | int i,j; | ||
627 | for (i = 0; i < root_container.children->length; ++i) { | ||
628 | swayc_t *op = root_container.children->items[i]; | ||
629 | for (j = 0; j < op->children->length; ++j) { | ||
630 | swayc_t *ws = op->children->items[j]; | ||
631 | if (method == SET) { | ||
632 | ws->gaps = amount; | ||
633 | } else if ((ws->gaps += amount) < 0) { | ||
634 | ws->gaps = 0; | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | arrange_windows(&root_container, -1, -1); | ||
639 | } else { | ||
640 | // Resize gaps for all views in workspace | ||
641 | swayc_t *top; | ||
642 | if (target == WORKSPACE) { | ||
643 | if ((top = swayc_active_workspace()) == NULL) { | ||
644 | return false; | ||
645 | } | ||
646 | } else { | ||
647 | top = &root_container; | ||
648 | } | ||
649 | int top_gap = top->gaps; | ||
650 | container_map(top, method == SET ? set_gaps : add_gaps, &amount); | ||
651 | top->gaps = top_gap; | ||
652 | arrange_windows(top, -1, -1); | ||
653 | } | ||
654 | |||
550 | return true; | 655 | return true; |
551 | } | 656 | } |
552 | 657 | ||
@@ -975,10 +1080,10 @@ bool handle_command(struct sway_config *config, char *exec) { | |||
975 | char **argv = split_directive(exec + strlen(handler->command), &argc); | 1080 | char **argv = split_directive(exec + strlen(handler->command), &argc); |
976 | int i; | 1081 | int i; |
977 | 1082 | ||
978 | // Perform var subs on all parts of the command | 1083 | // Perform var subs on all parts of the command |
979 | for (i = 0; i < argc; ++i) { | 1084 | for (i = 0; i < argc; ++i) { |
980 | argv[i] = do_var_replacement(config, argv[i]); | 1085 | argv[i] = do_var_replacement(config, argv[i]); |
981 | } | 1086 | } |
982 | 1087 | ||
983 | exec_success = handler->handle(config, argc, argv); | 1088 | exec_success = handler->handle(config, argc, argv); |
984 | for (i = 0; i < argc; ++i) { | 1089 | for (i = 0; i < argc; ++i) { |