diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-04 06:58:26 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-04 06:58:26 -0500 |
commit | 713c7d6e1eb886de374659d41ae4cab0f4bc3f34 (patch) | |
tree | 2d86515c4b941603af6336e386f35e4b169e9135 | |
parent | Merge pull request #205 from sce/focus_move_cont_to_adjacent_output (diff) | |
parent | commands: gaps: Re-arrange windows after changing default gaps. (diff) | |
download | sway-713c7d6e1eb886de374659d41ae4cab0f4bc3f34.tar.gz sway-713c7d6e1eb886de374659d41ae4cab0f4bc3f34.tar.zst sway-713c7d6e1eb886de374659d41ae4cab0f4bc3f34.zip |
Merge pull request #215 from sce/gaps
Clean up gaps command
-rw-r--r-- | sway.5.txt | 8 | ||||
-rw-r--r-- | sway/commands.c | 25 |
2 files changed, 16 insertions, 17 deletions
@@ -69,18 +69,18 @@ Commands | |||
69 | Toggles fullscreen status for the focused view. | 69 | Toggles fullscreen status for the focused view. |
70 | 70 | ||
71 | **gaps** <amount>:: | 71 | **gaps** <amount>:: |
72 | Sets _amount_ pixels as the gap between each view, and around each | 72 | Sets default _amount_ pixels as the gap between each view, and around each |
73 | workspace. | 73 | workspace. |
74 | 74 | ||
75 | **gaps** <inner|outer> <amount>:: | 75 | **gaps** <inner|outer> <amount>:: |
76 | Sets _amount_ pixels as the _inner_ or _outer_ gap, where the former affects | 76 | Sets default _amount_ pixels as the _inner_ or _outer_ gap, where the former |
77 | spacing between views and the latter affects the space around each | 77 | affects spacing between views and the latter affects the space around each |
78 | workspace. | 78 | workspace. |
79 | 79 | ||
80 | **gaps** <inner|outer> <all|workspace|current> <set|plus|minus> <amount>:: | 80 | **gaps** <inner|outer> <all|workspace|current> <set|plus|minus> <amount>:: |
81 | Changes the gaps for the _inner_ or _outer_ gap. _all_ changes the gaps for | 81 | Changes the gaps for the _inner_ or _outer_ gap. _all_ changes the gaps for |
82 | all views or workspace, _workspace_ changes gaps for all views in current | 82 | all views or workspace, _workspace_ changes gaps for all views in current |
83 | workspace, or current workspace, and _current_ changes gaps for the current | 83 | workspace (or current workspace), and _current_ changes gaps for the current |
84 | view or workspace. | 84 | view or workspace. |
85 | 85 | ||
86 | **kill**:: | 86 | **kill**:: |
diff --git a/sway/commands.c b/sway/commands.c index 43166a1c..19b8e1a9 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -760,26 +760,24 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { | |||
760 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { | 760 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { |
761 | return error; | 761 | return error; |
762 | } | 762 | } |
763 | const char* expected_syntax = | ||
764 | "Expected 'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"; | ||
763 | const char *amount_str = argv[0]; | 765 | const char *amount_str = argv[0]; |
764 | // gaps amount | 766 | // gaps amount |
765 | if (argc >= 1 && isdigit(*amount_str)) { | 767 | if (argc >= 1 && isdigit(*amount_str)) { |
766 | int amount = (int)strtol(amount_str, NULL, 10); | 768 | int amount = (int)strtol(amount_str, NULL, 10); |
767 | if (errno == ERANGE || amount == 0) { | 769 | if (errno == ERANGE) { |
768 | errno = 0; | 770 | errno = 0; |
769 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | 771 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); |
770 | } | 772 | } |
771 | if (config->gaps_inner == 0) { | 773 | config->gaps_inner = config->gaps_outer = amount; |
772 | config->gaps_inner = amount; | 774 | arrange_windows(&root_container, -1, -1); |
773 | } | ||
774 | if (config->gaps_outer == 0) { | ||
775 | config->gaps_outer = amount; | ||
776 | } | ||
777 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 775 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
778 | } | 776 | } |
779 | // gaps inner|outer n | 777 | // gaps inner|outer n |
780 | else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { | 778 | else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { |
781 | int amount = (int)strtol(amount_str, NULL, 10); | 779 | int amount = (int)strtol(amount_str, NULL, 10); |
782 | if (errno == ERANGE || amount == 0) { | 780 | if (errno == ERANGE) { |
783 | errno = 0; | 781 | errno = 0; |
784 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | 782 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); |
785 | } | 783 | } |
@@ -789,11 +787,12 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { | |||
789 | } else if (strcasecmp(target_str, "outer") == 0) { | 787 | } else if (strcasecmp(target_str, "outer") == 0) { |
790 | config->gaps_outer = amount; | 788 | config->gaps_outer = amount; |
791 | } | 789 | } |
790 | arrange_windows(&root_container, -1, -1); | ||
792 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 791 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
793 | } | 792 | } |
794 | // gaps inner|outer current|all set|plus|minus n | 793 | // gaps inner|outer current|all set|plus|minus n |
795 | if (argc < 4 || config->reading) { | 794 | if (argc < 4 || config->reading) { |
796 | return cmd_results_new(CMD_INVALID, "gaps", "Expected 'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"); | 795 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); |
797 | } | 796 | } |
798 | // gaps inner|outer ... | 797 | // gaps inner|outer ... |
799 | const char *inout_str = argv[0]; | 798 | const char *inout_str = argv[0]; |
@@ -803,7 +802,7 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { | |||
803 | } else if (strcasecmp(inout_str, "outer") == 0) { | 802 | } else if (strcasecmp(inout_str, "outer") == 0) { |
804 | inout = OUTER; | 803 | inout = OUTER; |
805 | } else { | 804 | } else { |
806 | return cmd_results_new(CMD_INVALID, "gaps", "Expected 'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"); | 805 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); |
807 | } | 806 | } |
808 | 807 | ||
809 | // gaps ... current|all ... | 808 | // gaps ... current|all ... |
@@ -821,13 +820,13 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { | |||
821 | target = WORKSPACE; | 820 | target = WORKSPACE; |
822 | } | 821 | } |
823 | } else { | 822 | } else { |
824 | return cmd_results_new(CMD_INVALID, "gaps", "Expected 'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"); | 823 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); |
825 | } | 824 | } |
826 | 825 | ||
827 | // gaps ... n | 826 | // gaps ... n |
828 | amount_str = argv[3]; | 827 | amount_str = argv[3]; |
829 | int amount = (int)strtol(amount_str, NULL, 10); | 828 | int amount = (int)strtol(amount_str, NULL, 10); |
830 | if (errno == ERANGE || amount == 0) { | 829 | if (errno == ERANGE) { |
831 | errno = 0; | 830 | errno = 0; |
832 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | 831 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); |
833 | } | 832 | } |
@@ -843,7 +842,7 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { | |||
843 | method = ADD; | 842 | method = ADD; |
844 | amount *= -1; | 843 | amount *= -1; |
845 | } else { | 844 | } else { |
846 | return cmd_results_new(CMD_INVALID, "gaps", "Expected 'gaps <inner|outer> <current|all> <set|plus|minus n>'"); | 845 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); |
847 | } | 846 | } |
848 | 847 | ||
849 | if (target == CURRENT) { | 848 | if (target == CURRENT) { |