aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output/position.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-02 21:33:16 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-03 10:26:06 -0400
commit5ea4a4d3eec897b915003ad7fc2b2e274d1a59c1 (patch)
tree8d077f70c7bc462f1987e8d57003a2b11de718ca /sway/commands/output/position.c
parentMerge pull request #2093 from emersion/damage-debug (diff)
downloadsway-5ea4a4d3eec897b915003ad7fc2b2e274d1a59c1.tar.gz
sway-5ea4a4d3eec897b915003ad7fc2b2e274d1a59c1.tar.zst
sway-5ea4a4d3eec897b915003ad7fc2b2e274d1a59c1.zip
Refactor cmd_output to use config_subcommand
Diffstat (limited to 'sway/commands/output/position.c')
-rw-r--r--sway/commands/output/position.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/sway/commands/output/position.c b/sway/commands/output/position.c
new file mode 100644
index 00000000..c2aeb281
--- /dev/null
+++ b/sway/commands/output/position.c
@@ -0,0 +1,46 @@
1#include <strings.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4
5struct cmd_results *output_cmd_position(int argc, char **argv) {
6 if (!config->handler_context.output_config) {
7 return cmd_results_new(CMD_FAILURE, "output", "Missing output config");
8 }
9 if (!argc) {
10 return cmd_results_new(CMD_INVALID, "output",
11 "Missing position argument.");
12 }
13
14 char *end;
15 config->handler_context.output_config->x = strtol(*argv, &end, 10);
16 if (*end) {
17 // Format is 1234,4321
18 if (*end != ',') {
19 return cmd_results_new(CMD_INVALID, "output",
20 "Invalid position x.");
21 }
22 ++end;
23 config->handler_context.output_config->y = strtol(end, &end, 10);
24 if (*end) {
25 return cmd_results_new(CMD_INVALID, "output",
26 "Invalid position y.");
27 }
28 } else {
29 // Format is 1234 4321 (legacy)
30 if (!argc) {
31 return cmd_results_new(CMD_INVALID, "output",
32 "Missing position argument (y).");
33 }
34 argc--; argv++;
35 config->handler_context.output_config->y = strtol(*argv, &end, 10);
36 if (*end) {
37 return cmd_results_new(CMD_INVALID, "output",
38 "Invalid position y.");
39 }
40 }
41
42 config->handler_context.leftovers.argc = argc - 1;
43 config->handler_context.leftovers.argv = argv + 1;
44 return NULL;
45}
46