diff options
Diffstat (limited to 'sway/commands/gaps.c')
-rw-r--r-- | sway/commands/gaps.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index faaeab37..021df843 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c | |||
@@ -43,7 +43,7 @@ static void prevent_invalid_outer_gaps(void) { | |||
43 | } | 43 | } |
44 | 44 | ||
45 | // gaps inner|outer|horizontal|vertical|top|right|bottom|left <px> | 45 | // gaps inner|outer|horizontal|vertical|top|right|bottom|left <px> |
46 | static const char *expected_defaults = | 46 | static const char expected_defaults[] = |
47 | "'gaps inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; | 47 | "'gaps inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; |
48 | static struct cmd_results *gaps_set_defaults(int argc, char **argv) { | 48 | static struct cmd_results *gaps_set_defaults(int argc, char **argv) { |
49 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); | 49 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); |
@@ -54,8 +54,7 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) { | |||
54 | char *end; | 54 | char *end; |
55 | int amount = strtol(argv[1], &end, 10); | 55 | int amount = strtol(argv[1], &end, 10); |
56 | if (strlen(end) && strcasecmp(end, "px") != 0) { | 56 | if (strlen(end) && strcasecmp(end, "px") != 0) { |
57 | return cmd_results_new(CMD_INVALID, "gaps", | 57 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults); |
58 | "Expected %s", expected_defaults); | ||
59 | } | 58 | } |
60 | 59 | ||
61 | bool valid = false; | 60 | bool valid = false; |
@@ -85,12 +84,11 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) { | |||
85 | } | 84 | } |
86 | } | 85 | } |
87 | if (!valid) { | 86 | if (!valid) { |
88 | return cmd_results_new(CMD_INVALID, "gaps", | 87 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults); |
89 | "Expected %s", expected_defaults); | ||
90 | } | 88 | } |
91 | 89 | ||
92 | prevent_invalid_outer_gaps(); | 90 | prevent_invalid_outer_gaps(); |
93 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 91 | return cmd_results_new(CMD_SUCCESS, NULL); |
94 | } | 92 | } |
95 | 93 | ||
96 | static void apply_gaps_op(int *prop, enum gaps_op op, int amount) { | 94 | static void apply_gaps_op(int *prop, enum gaps_op op, int amount) { |
@@ -136,7 +134,7 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) { | |||
136 | 134 | ||
137 | // gaps inner|outer|horizontal|vertical|top|right|bottom|left current|all | 135 | // gaps inner|outer|horizontal|vertical|top|right|bottom|left current|all |
138 | // set|plus|minus <px> | 136 | // set|plus|minus <px> |
139 | static const char *expected_runtime = "'gaps inner|outer|horizontal|vertical|" | 137 | static const char expected_runtime[] = "'gaps inner|outer|horizontal|vertical|" |
140 | "top|right|bottom|left current|all set|plus|minus <px>'"; | 138 | "top|right|bottom|left current|all set|plus|minus <px>'"; |
141 | static struct cmd_results *gaps_set_runtime(int argc, char **argv) { | 139 | static struct cmd_results *gaps_set_runtime(int argc, char **argv) { |
142 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); | 140 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); |
@@ -144,7 +142,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { | |||
144 | return error; | 142 | return error; |
145 | } | 143 | } |
146 | if (!root->outputs->length) { | 144 | if (!root->outputs->length) { |
147 | return cmd_results_new(CMD_INVALID, "gaps", | 145 | return cmd_results_new(CMD_INVALID, |
148 | "Can't run this command while there's no outputs connected."); | 146 | "Can't run this command while there's no outputs connected."); |
149 | } | 147 | } |
150 | 148 | ||
@@ -164,8 +162,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { | |||
164 | } | 162 | } |
165 | if (!data.inner && !data.outer.top && !data.outer.right && | 163 | if (!data.inner && !data.outer.top && !data.outer.right && |
166 | !data.outer.bottom && !data.outer.left) { | 164 | !data.outer.bottom && !data.outer.left) { |
167 | return cmd_results_new(CMD_INVALID, "gaps", | 165 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime); |
168 | "Expected %s", expected_runtime); | ||
169 | } | 166 | } |
170 | 167 | ||
171 | bool all; | 168 | bool all; |
@@ -174,8 +171,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { | |||
174 | } else if (strcasecmp(argv[1], "all") == 0) { | 171 | } else if (strcasecmp(argv[1], "all") == 0) { |
175 | all = true; | 172 | all = true; |
176 | } else { | 173 | } else { |
177 | return cmd_results_new(CMD_INVALID, "gaps", | 174 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime); |
178 | "Expected %s", expected_runtime); | ||
179 | } | 175 | } |
180 | 176 | ||
181 | if (strcasecmp(argv[2], "set") == 0) { | 177 | if (strcasecmp(argv[2], "set") == 0) { |
@@ -185,15 +181,13 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { | |||
185 | } else if (strcasecmp(argv[2], "minus") == 0) { | 181 | } else if (strcasecmp(argv[2], "minus") == 0) { |
186 | data.operation = GAPS_OP_SUBTRACT; | 182 | data.operation = GAPS_OP_SUBTRACT; |
187 | } else { | 183 | } else { |
188 | return cmd_results_new(CMD_INVALID, "gaps", | 184 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime); |
189 | "Expected %s", expected_runtime); | ||
190 | } | 185 | } |
191 | 186 | ||
192 | char *end; | 187 | char *end; |
193 | data.amount = strtol(argv[3], &end, 10); | 188 | data.amount = strtol(argv[3], &end, 10); |
194 | if (strlen(end) && strcasecmp(end, "px") != 0) { | 189 | if (strlen(end) && strcasecmp(end, "px") != 0) { |
195 | return cmd_results_new(CMD_INVALID, "gaps", | 190 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime); |
196 | "Expected %s", expected_runtime); | ||
197 | } | 191 | } |
198 | 192 | ||
199 | if (all) { | 193 | if (all) { |
@@ -202,7 +196,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { | |||
202 | configure_gaps(config->handler_context.workspace, &data); | 196 | configure_gaps(config->handler_context.workspace, &data); |
203 | } | 197 | } |
204 | 198 | ||
205 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 199 | return cmd_results_new(CMD_SUCCESS, NULL); |
206 | } | 200 | } |
207 | 201 | ||
208 | // gaps inner|outer|<dir>|<side> <px> - sets defaults for workspaces | 202 | // gaps inner|outer|<dir>|<side> <px> - sets defaults for workspaces |
@@ -224,9 +218,8 @@ struct cmd_results *cmd_gaps(int argc, char **argv) { | |||
224 | return gaps_set_runtime(argc, argv); | 218 | return gaps_set_runtime(argc, argv); |
225 | } | 219 | } |
226 | if (config_loading) { | 220 | if (config_loading) { |
227 | return cmd_results_new(CMD_INVALID, "gaps", | 221 | return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults); |
228 | "Expected %s", expected_defaults); | ||
229 | } | 222 | } |
230 | return cmd_results_new(CMD_INVALID, "gaps", | 223 | return cmd_results_new(CMD_INVALID, "Expected %s or %s", |
231 | "Expected %s or %s", expected_runtime, expected_defaults); | 224 | expected_runtime, expected_defaults); |
232 | } | 225 | } |