2018-06-03 11:33:16 +10:00
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
|
|
|
|
struct cmd_results *output_cmd_mode(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 mode argument.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
struct output_config *output = config->handler_context.output_config;
|
|
|
|
|
2019-10-27 07:36:49 +11:00
|
|
|
if (strcmp(argv[0], "--custom") == 0) {
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
output->custom_mode = 1;
|
|
|
|
} else {
|
|
|
|
output->custom_mode = 0;
|
|
|
|
}
|
|
|
|
|
2018-06-03 11:33:16 +10:00
|
|
|
char *end;
|
|
|
|
output->width = strtol(*argv, &end, 10);
|
|
|
|
if (*end) {
|
|
|
|
// Format is 1234x4321
|
|
|
|
if (*end != 'x') {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid mode width.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
++end;
|
|
|
|
output->height = strtol(end, &end, 10);
|
|
|
|
if (*end) {
|
|
|
|
if (*end != '@') {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid mode height.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
++end;
|
|
|
|
output->refresh_rate = strtof(end, &end);
|
|
|
|
if (strcasecmp("Hz", end) != 0) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2018-06-03 11:33:16 +10:00
|
|
|
"Invalid mode refresh rate.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Format is 1234 4321
|
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,
|
2018-06-03 11:33:16 +10:00
|
|
|
"Missing mode argument (height).");
|
|
|
|
}
|
|
|
|
output->height = strtol(*argv, &end, 10);
|
|
|
|
if (*end) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid mode height.");
|
2018-06-03 11:33:16 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config->handler_context.leftovers.argc = argc - 1;
|
|
|
|
config->handler_context.leftovers.argv = argv + 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|