2018-06-03 11:33:16 +10:00
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
|
|
|
|
struct cmd_results *output_cmd_position(int argc, char **argv) {
|
|
|
|
if (!config->handler_context.output_config) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_FAILURE, "Missing output config");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
if (!argc) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Missing position argument.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
char *end;
|
|
|
|
config->handler_context.output_config->x = strtol(*argv, &end, 10);
|
|
|
|
if (*end) {
|
|
|
|
// Format is 1234,4321
|
|
|
|
if (*end != ',') {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid position x.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
++end;
|
|
|
|
config->handler_context.output_config->y = strtol(end, &end, 10);
|
|
|
|
if (*end) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid position y.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Format is 1234 4321 (legacy)
|
2018-06-30 23:16:54 +10:00
|
|
|
argc--; argv++;
|
2018-06-03 11:33:16 +10:00
|
|
|
if (!argc) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Missing position argument (y).");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
config->handler_context.output_config->y = strtol(*argv, &end, 10);
|
|
|
|
if (*end) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid position y.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config->handler_context.leftovers.argc = argc - 1;
|
|
|
|
config->handler_context.leftovers.argv = argv + 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|