summaryrefslogtreecommitdiffstats
path: root/sway/commands/output/position.c
diff options
context:
space:
mode:
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